Skip to content

Commit

Permalink
Fix php-cs-fixer workflow (#206)
Browse files Browse the repository at this point in the history
* rename php-cs-fixer config file

* update php-cs-fixer workflow to use new config filename

* Fix styling

* wip
  • Loading branch information
patinthehat authored Dec 9, 2022
1 parent 859b08e commit c83105c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 40 deletions.
30 changes: 15 additions & 15 deletions .github/workflows/php-cs-fixer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@ name: Check & fix styling
on: [push]

jobs:
php-cs-fixer:
runs-on: ubuntu-latest
php-cs-fixer:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
ref: ${{ github.head_ref }}

- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php_cs.dist --allow-risky=yes
- name: Run PHP CS Fixer
uses: docker://oskarstark/php-cs-fixer-ga
with:
args: --config=.php-cs-fixer.dist.php --allow-risky=yes

- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
- name: Commit changes
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Fix styling
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ docs
vendor
.php_cs.cache
.phpunit.result.cache
*.cache
13 changes: 8 additions & 5 deletions .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
<?php

$finder = Symfony\Component\Finder\Finder::create()
->notPath('bootstrap/*')
->notPath('storage/*')
->notPath('resources/view/mail/*')
->in([
__DIR__ . '/src',
__DIR__ . '/tests',
Expand All @@ -10,14 +13,14 @@
->ignoreDotFiles(true)
->ignoreVCS(true);

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config)
->setRules([
'@PSR2' => true,
'@PSR12' => true,
'array_syntax' => ['syntax' => 'short'],
'ordered_imports' => ['sortAlgorithm' => 'alpha'],
'ordered_imports' => ['sort_algorithm' => 'alpha'],
'no_unused_imports' => true,
'not_operator_with_successor_space' => true,
'trailing_comma_in_multiline_array' => true,
'trailing_comma_in_multiline' => true,
'phpdoc_scalar' => true,
'unary_operator_spaces' => true,
'binary_operator_spaces' => true,
Expand All @@ -28,7 +31,7 @@
'phpdoc_var_without_name' => true,
'class_attributes_separation' => [
'elements' => [
'method',
'method' => 'one'
],
],
'method_argument_space' => [
Expand Down
25 changes: 12 additions & 13 deletions src/Pdf.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Spatie\PdfToImage;

use Imagick;
use ImagickException;
use Spatie\PdfToImage\Exceptions\InvalidFormat;
use Spatie\PdfToImage\Exceptions\PageDoesNotExist;
use Spatie\PdfToImage\Exceptions\PdfDoesNotExist;
Expand Down Expand Up @@ -126,23 +125,23 @@ public function saveImage(string $pathToImage): bool
}

public function saveAllPagesAsImages(string $directory, string $prefix = ''): array
{
$numberOfPages = $this->getNumberOfPages();
{
$numberOfPages = $this->getNumberOfPages();

if ($numberOfPages === 0) {
return [];
}
if ($numberOfPages === 0) {
return [];
}

return array_map(function ($pageNumber) use ($directory, $prefix) {
$this->setPage($pageNumber);
return array_map(function ($pageNumber) use ($directory, $prefix) {
$this->setPage($pageNumber);

$destination = "{$directory}/{$prefix}{$pageNumber}.{$this->outputFormat}";
$destination = "{$directory}/{$prefix}{$pageNumber}.{$this->outputFormat}";

$this->saveImage($destination);
$this->saveImage($destination);

return $destination;
}, range(1, $numberOfPages));
}
return $destination;
}, range(1, $numberOfPages));
}

public function getImageData(string $pathToImage): Imagick
{
Expand Down
14 changes: 7 additions & 7 deletions tests/PdfTest.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<?php

use Spatie\PdfToImage\Pdf;
use Spatie\PdfToImage\Exceptions\InvalidFormat;
use Spatie\PdfToImage\Exceptions\PdfDoesNotExist;
use Spatie\PdfToImage\Exceptions\PageDoesNotExist;
use Spatie\PdfToImage\Exceptions\PdfDoesNotExist;
use Spatie\PdfToImage\Pdf;

beforeEach(function () {
$this->testFile = __DIR__.'/files/test.pdf';
Expand Down Expand Up @@ -78,11 +78,11 @@
expect($imagick->getCompressionQuality())->toEqual(99);
});

it('will create a thumbnail at specified width', function() {
$imagick = (new Pdf($this->multipageTestFile))
->width(400)
->getImageData('test.jpg')
->getImageGeometry();
it('will create a thumbnail at specified width', function () {
$imagick = (new Pdf($this->multipageTestFile))
->width(400)
->getImageData('test.jpg')
->getImageGeometry();

expect($imagick['width'])->toBe(400);
});

0 comments on commit c83105c

Please sign in to comment.