Skip to content

Commit

Permalink
Merge pull request #80 from peter279k/improve_stuffs
Browse files Browse the repository at this point in the history
Upgrade PHPStan & PHP-CS-Fixer and improve scripts
  • Loading branch information
odan committed Dec 8, 2021
2 parents a7aa0cf + f79968d commit 3d2e06c
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 40 deletions.
6 changes: 3 additions & 3 deletions .cs.php
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?php

return PhpCsFixer\Config::create()
return (new PhpCsFixer\Config())
->setUsingCache(false)
->setRiskyAllowed(true)
//->setCacheFile(__DIR__ . '/.php_cs.cache')
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'psr4' => true,
'psr_autoloading' => true,
'yoda_style' => false,
'array_syntax' => ['syntax' => 'short'],
'list_syntax' => ['syntax' => 'short'],
Expand All @@ -17,7 +17,7 @@
'compact_nullable_typehint' => true,
'increment_style' => ['style' => 'post'],
'declare_equal_normalize' => ['space' => 'single'],
'no_short_echo_tag' => true,
'echo_tag_syntax' => ['format' => 'long'],
'protected_to_private' => false,
'phpdoc_align' => false,
'phpdoc_add_missing_param_annotation' => ['only_untyped' => false],
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
uses: actions/checkout@v1

- name: Setup PHP
uses: shivammathur/setup-php@v1
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-versions }}
extensions: mbstring, pdo, pdo_mysql, intl, zip
Expand All @@ -38,4 +38,4 @@ jobs:
run: composer install --prefer-dist --no-progress --no-suggest

- name: Run test suite
run: composer check-all
run: composer check
31 changes: 16 additions & 15 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,26 @@
"require-dev": {
"overtrue/phplint": "^1.1",
"phpunit/phpunit": "^8",
"phpstan/phpstan": "^0.12",
"squizlabs/php_codesniffer": "^3.4"
"phpstan/phpstan": "^1",
"squizlabs/php_codesniffer": "^3.4",
"friendsofphp/php-cs-fixer": "^3"
},
"scripts": {
"test": "phpunit --configuration phpunit.xml",
"test-coverage": "phpunit --configuration phpunit.xml --coverage-clover build/logs/clover.xml --coverage-html build/coverage",
"check-style": "phpcs --standard=phpcs.xml",
"fix-style": "phpcbf --standard=phpcs.xml",
"phpstan": "phpstan analyse src tests --level=max -c phpstan.neon --no-progress",
"lint": "phplint ./ --exclude=vendor --no-interaction --no-cache",
"install-cs": "php -r \"@mkdir('build'); copy('https://cs.symfony.com/download/php-cs-fixer-v2.phar', 'build/php-cs-fixer-v2.phar');\"",
"fix-cs": "php build/php-cs-fixer-v2.phar fix --config=.cs.php",
"check-cs": "php build/php-cs-fixer-v2.phar fix --dry-run --format=txt --verbose --diff --diff-format=udiff --config=.cs.php",
"check-all": [
"check": [
"@lint",
"@check-style",
"@cs:check",
"@sniffer:check",
"@phpstan",
"@test-coverage"
]
"@test:coverage"
],
"cs:check": "php-cs-fixer fix --dry-run --format=txt --verbose --diff --config=.cs.php",
"cs:fix": "php-cs-fixer fix --config=.cs.php",
"lint": "phplint ./ --exclude=vendor --no-interaction --no-cache",
"phpstan": "phpstan analyse -c phpstan.neon --no-progress --ansi",
"sniffer:check": "phpcs --standard=phpcs.xml",
"sniffer:fix": "phpcbf --standard=phpcs.xml",
"test": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always",
"test:coverage": "phpunit --configuration phpunit.xml --do-not-cache-result --colors=always --coverage-clover build/logs/clover.xml --coverage-html build/coverage"
},
"autoload": {
"psr-4": {
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src
- tests
2 changes: 1 addition & 1 deletion src/Detector/JpegDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ final class JpegDetector implements DetectorInterface
*/
public function detect(SplFileObject $file): ?ImageType
{
return $file->fread(2) === chr(0xFF) . chr(0xd8) ? new ImageType(
return $file->fread(2) === chr(0xFF) . chr(0xD8) ? new ImageType(
ImageFormat::JPEG,
MimeType::IMAGE_JPEG
) : null;
Expand Down
4 changes: 0 additions & 4 deletions src/ImageTypeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ public function addDetector(DetectorInterface $detector): void
* Add image detector provider.
*
* @param ProviderInterface $provider The provider
*
* @return void
*/
public function addProvider(ProviderInterface $provider): void
{
Expand Down Expand Up @@ -64,8 +62,6 @@ public function getImageTypeFromFile(SplFileObject $file): ImageType
* Reads and returns the type of the image.
*
* @param SplFileObject $file The image file
*
* @return ImageType|null
*/
private function detectFile(SplFileObject $file): ?ImageType
{
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/HdrProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
use Selective\ImageType\Detector\CineonDetector;
use Selective\ImageType\Detector\DpxDetector;
use Selective\ImageType\Detector\ExrDetector;
use Selective\ImageType\Detector\HdrDetector;
use Selective\ImageType\Detector\JpegHdrDetector;
use Selective\ImageType\Detector\PbmDetector;
use Selective\ImageType\Detector\PfmDetector;
use Selective\ImageType\Detector\HdrDetector;

/**
* Provider.
Expand Down
4 changes: 2 additions & 2 deletions src/Provider/RasterProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
use Selective\ImageType\Detector\JpmDetector;
use Selective\ImageType\Detector\MngDetector;
use Selective\ImageType\Detector\PdnDetector;
use Selective\ImageType\Detector\PgmDetector;
use Selective\ImageType\Detector\PngDetector;
use Selective\ImageType\Detector\PpmDetector;
use Selective\ImageType\Detector\PsbDetector;
use Selective\ImageType\Detector\PsdDetector;
use Selective\ImageType\Detector\SvgDetector;
use Selective\ImageType\Detector\SwfDetector;
use Selective\ImageType\Detector\TiffDetector;
use Selective\ImageType\Detector\WebpDetector;
use Selective\ImageType\Detector\XcfDetector;
use Selective\ImageType\Detector\PgmDetector;
use Selective\ImageType\Detector\PpmDetector;

/**
* Raster Provider.
Expand Down
2 changes: 1 addition & 1 deletion src/Provider/RawProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

use Selective\ImageType\Detector\Cr2Detector;
use Selective\ImageType\Detector\Cr3Detector;
use Selective\ImageType\Detector\DngDetector;
use Selective\ImageType\Detector\Fr3Detector;
use Selective\ImageType\Detector\OrfDetector;
use Selective\ImageType\Detector\PefDetector;
use Selective\ImageType\Detector\Rw2Detector;
use Selective\ImageType\Detector\DngDetector;

/**
* Provider.
Expand Down
6 changes: 1 addition & 5 deletions tests/ImageTypeDetectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
use Selective\ImageType\ImageTypeDetectorException;
use Selective\ImageType\MimeType;
use Selective\ImageType\Provider\CompoundProvider;
use Selective\ImageType\Provider\RasterProvider;
use Selective\ImageType\Provider\HdrProvider;
use Selective\ImageType\Provider\RasterProvider;
use Selective\ImageType\Provider\RawProvider;
use Selective\ImageType\Provider\VectorProvider;
use SplFileObject;
Expand Down Expand Up @@ -47,8 +47,6 @@ private function createDetector(): ImageTypeDetector
* @param string $file The file
* @param string $format The expected format
* @param string $mime The expected mime type
*
* @return void
*/
public function testGetImageTypeFromFile(string $file, string $format, string $mime): void
{
Expand Down Expand Up @@ -136,8 +134,6 @@ public function providerGetImageTypeFromFile(): array

/**
* Test.
*
* @return void
*/
public function testGetImageTypeWithUnknownFormat(): void
{
Expand Down
6 changes: 0 additions & 6 deletions tests/ImageTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ class ImageTypeTest extends TestCase
{
/**
* Test.
*
* @return void
*/
public function testCreateInstance(): void
{
Expand All @@ -28,8 +26,6 @@ public function testCreateInstance(): void

/**
* Test.
*
* @return void
*/
public function testCreateInstanceWithError(): void
{
Expand All @@ -39,8 +35,6 @@ public function testCreateInstanceWithError(): void

/**
* Test.
*
* @return void
*/
public function testCreateInstanceWithError2(): void
{
Expand Down

0 comments on commit 3d2e06c

Please sign in to comment.