Skip to content

Commit

Permalink
Merge pull request #263 from j0k3r/fix/php-cs-fixer-phpstan
Browse files Browse the repository at this point in the history
Update PHP-CS-Fixer to 3.0
  • Loading branch information
j0k3r authored Jun 1, 2021
2 parents b5c5129 + a519a36 commit d92a656
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 62 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/coding-standards.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
with:
coverage: "none"
php-version: "${{ matrix.php }}"
tools: cs2pr, composer:v1
tools: cs2pr, composer:v2
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
33 changes: 11 additions & 22 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: composer:v1
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "pcov"
tools: composer:v1
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: composer:v1
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
Expand Down Expand Up @@ -154,7 +154,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: composer:v1
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
Expand Down Expand Up @@ -194,7 +194,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: composer:v1
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
Expand Down Expand Up @@ -234,7 +234,7 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: composer:v1
tools: composer:v2
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
Expand All @@ -255,8 +255,8 @@ jobs:
- name: "Run PHPUnit"
run: "php vendor/bin/simple-phpunit -v"

phpunit-composerv2:
name: "PHPUnit Composer v2 (PHP ${{ matrix.php }})"
phpunit-composerv1:
name: "PHPUnit Composer v1 (PHP ${{ matrix.php }})"
runs-on: "ubuntu-18.04"

strategy:
Expand All @@ -275,25 +275,14 @@ jobs:
with:
php-version: "${{ matrix.php }}"
coverage: "none"
tools: composer:v2
tools: composer:v1
extensions: tidy
ini-values: "date.timezone=Europe/Paris"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: "Cache dependencies installed with Composer"
uses: "actions/cache@v2"
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: "php-${{ matrix.php }}-composer-locked-${{ hashFiles('composer.lock') }}"
restore-keys: "php-${{ matrix.php }}-composer-locked-"

- name: "Install dependencies with composer"
run: "composer update --no-interaction --optimize-autoloader --no-progress --prefer-dist"
- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v1"

- name: "Setup logs"
run: "mkdir -p build/logs"
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
log/graby.log
log/html.log
composer.lock
.php_cs.cache
/.php-cs-fixer.cache
.phpunit.result.cache
17 changes: 9 additions & 8 deletions .php_cs → .php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
<?php

return PhpCsFixer\Config::create()

$finder = (new PhpCsFixer\Finder())
->in(__DIR__)
->exclude(['vendor', 'log'])
;
return (new PhpCsFixer\Config())
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'array_syntax' => ['syntax' => 'short'],
'combine_consecutive_unsets' => true,
'heredoc_to_nowdoc' => true,
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'],
'no_extra_blank_lines' => ['tokens' => ['break', 'continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block']],
'no_unreachable_default_argument_value' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_strict' => false,
'php_unit_strict' => true,
'phpdoc_order' => true,
// 'psr4' => true,
'strict_comparison' => true,
'strict_param' => true,
'concat_space' => ['spacing' => 'one'],
])
->setFinder(
PhpCsFixer\Finder::create()
->exclude(['vendor', 'log'])
->in(__DIR__)
)
->setFinder($finder)
;
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"minimum-stability": "dev",
"prefer-stable": true,
"require": {
"php": ">=7.1",
"php": ">=7.1.3",
"ext-curl": "*",
"ext-tidy": "*",
"fossar/htmlawed": "^1.2.7",
Expand All @@ -34,7 +34,7 @@
"true/punycode": "^2.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16",
"friendsofphp/php-cs-fixer": "^3.0",
"guzzlehttp/guzzle": "^6.3.0",
"php-http/guzzle6-adapter": "^2.0",
"php-http/mock-client": "^1.4",
Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ parameters:
- tests

bootstrapFiles:
- vendor/bin/.phpunit/phpunit-8.3-0/vendor/autoload.php
- vendor/bin/.phpunit/phpunit-8.5-0/vendor/autoload.php

ignoreErrors:
# because we check for some HTTP client to exist or not (Guzzle 5/6 & cURL)
Expand Down
2 changes: 1 addition & 1 deletion tests/Extractor/ContentExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ public function testProcessFindString(): void

$this->assertStringContainsString('<iframe class="video"', $content_block->ownerDocument->saveXML($content_block));
$this->assertCount(1, $contentExtractor->getAuthors());
$this->assertEquals('CaTV', $contentExtractor->getAuthors()[0]);
$this->assertSame('CaTV', $contentExtractor->getAuthors()[0]);
}

/**
Expand Down
20 changes: 10 additions & 10 deletions tests/Extractor/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ public function testFetchHeadGoodContentType(): void
/** @var RequestInterface $request */
$request = $httpMockClient->getRequests()[0];

$this->assertEquals('Mozilla/5.2', $request->getHeaderLine('User-Agent'));
$this->assertEquals('http://www.google.co.uk/url?sa=t&source=web&cd=1', $request->getHeaderLine('Referer'));
$this->assertSame('Mozilla/5.2', $request->getHeaderLine('User-Agent'));
$this->assertSame('http://www.google.co.uk/url?sa=t&source=web&cd=1', $request->getHeaderLine('Referer'));
$this->assertSame($url, $res['effective_url']);
$this->assertSame('yay', $res['body']);
$this->assertSame('image/jpg', $res['headers']['content-type']);
Expand All @@ -80,8 +80,8 @@ public function testFetchHeadBadContentType(): void
$res = $http->fetch($url);

$this->assertCount(2, $httpMockClient->getRequests());
$this->assertEquals('HEAD', $httpMockClient->getRequests()[0]->getMethod(), 'first request is head because of the extension');
$this->assertEquals('GET', $httpMockClient->getRequests()[1]->getMethod(), 'second request is get because the Content-Type wasn\'t a binary');
$this->assertSame('HEAD', $httpMockClient->getRequests()[0]->getMethod(), 'first request is head because of the extension');
$this->assertSame('GET', $httpMockClient->getRequests()[1]->getMethod(), 'second request is get because the Content-Type wasn\'t a binary');

$this->assertSame($url, $res['effective_url']);
$this->assertSame('yay', $res['body']);
Expand All @@ -101,8 +101,8 @@ public function testFetchHeadReallyBadContentType(): void
$res = $http->fetch($url);

$this->assertCount(2, $httpMockClient->getRequests());
$this->assertEquals('HEAD', $httpMockClient->getRequests()[0]->getMethod(), 'first request should be HEAD because of the extension');
$this->assertEquals('GET', $httpMockClient->getRequests()[1]->getMethod(), 'second request is GET because the Content-Type wasn\'t a binary');
$this->assertSame('HEAD', $httpMockClient->getRequests()[0]->getMethod(), 'first request should be HEAD because of the extension');
$this->assertSame('GET', $httpMockClient->getRequests()[1]->getMethod(), 'second request is GET because the Content-Type wasn\'t a binary');

$this->assertSame($url, $res['effective_url']);
$this->assertSame('yay', $res['body']);
Expand Down Expand Up @@ -149,10 +149,10 @@ public function testFetchGetWithMetaRefresh(string $url, string $body, string $m
$res = $http->fetch($url);

$this->assertCount(2, $httpMockClient->getRequests());
$this->assertEquals('GET', $httpMockClient->getRequests()[0]->getMethod());
$this->assertEquals($url, (string) $httpMockClient->getRequests()[0]->getUri());
$this->assertEquals('GET', $httpMockClient->getRequests()[1]->getMethod());
$this->assertEquals($metaUrl, (string) $httpMockClient->getRequests()[1]->getUri());
$this->assertSame('GET', $httpMockClient->getRequests()[0]->getMethod());
$this->assertSame($url, (string) $httpMockClient->getRequests()[0]->getUri());
$this->assertSame('GET', $httpMockClient->getRequests()[1]->getMethod());
$this->assertSame($metaUrl, (string) $httpMockClient->getRequests()[1]->getUri());

$this->assertSame($metaUrl, $res['effective_url']);
$this->assertEmpty($res['body']);
Expand Down
16 changes: 8 additions & 8 deletions tests/GrabyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class GrabyTest extends TestCase
/**
* A human IPv4 corresponding to example.com.
*/
const AN_IPV4 = '93.184.216.34';
public const AN_IPV4 = '93.184.216.34';

public function testConstructDefault(): void
{
Expand Down Expand Up @@ -262,8 +262,8 @@ public function testMimeTypeActionExclude(): void
$graby->fetchContent('http://example.com/virus.exe');

$this->assertCount(2, $httpMockClient->getRequests());
$this->assertEquals('HEAD', $httpMockClient->getRequests()[0]->getMethod());
$this->assertEquals('GET', $httpMockClient->getRequests()[1]->getMethod());
$this->assertSame('HEAD', $httpMockClient->getRequests()[0]->getMethod());
$this->assertSame('GET', $httpMockClient->getRequests()[1]->getMethod());
}

public function dataForExtension(): array
Expand All @@ -289,7 +289,7 @@ public function testAssetExtension(string $url, string $header, string $title, s
$res = $graby->fetchContent($url);

$this->assertCount(1, $httpMockClient->getRequests());
$this->assertEquals('HEAD', $httpMockClient->getRequests()[0]->getMethod());
$this->assertSame('HEAD', $httpMockClient->getRequests()[0]->getMethod());
$this->assertCount(11, $res);
$this->assertEmpty($res['language']);
$this->assertSame($title, $res['title']);
Expand Down Expand Up @@ -343,8 +343,8 @@ public function testAssetExtensionZIP(): void
$res = $graby->fetchContent('https://github.com/nathanaccidentally/Cydia-Repo-Template/archive/master.zip');

$this->assertCount(2, $httpMockClient->getRequests());
$this->assertEquals('HEAD', $httpMockClient->getRequests()[0]->getMethod());
$this->assertEquals('GET', $httpMockClient->getRequests()[1]->getMethod());
$this->assertSame('HEAD', $httpMockClient->getRequests()[0]->getMethod());
$this->assertSame('GET', $httpMockClient->getRequests()[1]->getMethod());

$this->assertCount(11, $res);
$this->assertEmpty($res['language']);
Expand Down Expand Up @@ -1082,8 +1082,8 @@ public function testMetaAuthor(): void
// The initial treatment was encapsulating the content into the empty node
// So we don't want to see that again
$authors = $res['authors'];
$this->assertEquals(1, \count($authors));
$this->assertEquals('Keith J. Grant', $authors[0]);
$this->assertCount(1, $authors);
$this->assertSame('Keith J. Grant', $authors[0]);
}

public function testJsonLd(): void
Expand Down
16 changes: 8 additions & 8 deletions tests/SiteConfig/ConfigBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public function testBuildFromArrayNoLines(): void
$configBuilder = new ConfigBuilder(['site_config' => [__DIR__]]);
$configActual = $configBuilder->parseLines([]);

$this->assertEquals($configBuilder->create(), $configActual);
$this->assertEqualsCanonicalizing($configBuilder->create(), $configActual);
}

public function testBuildFromArray(): void
Expand Down Expand Up @@ -68,7 +68,7 @@ public function testBuildFromArray(): void
],
];

$this->assertEquals($configExpected, $configActual);
$this->assertEqualsCanonicalizing($configExpected, $configActual);

// without using default value
$this->assertTrue(true === $configActual->tidy(false));
Expand Down Expand Up @@ -109,7 +109,7 @@ public function testAddToCache(string $key, string $cachedKey, string $expectedK

$configBuilder->addToCache($key, $config);

$this->assertEquals($config, $configBuilder->getCachedVersion($expectedKey));
$this->assertSame($config, $configBuilder->getCachedVersion($expectedKey));
}

public function dataForCachedVersion(): array
Expand All @@ -136,7 +136,7 @@ public function testCachedVersion(string $key, bool $cached): void
$configBuilder->addToCache($key, $config);
}

$this->assertEquals($config, $configBuilder->getCachedVersion($key));
$this->assertSame($config, $configBuilder->getCachedVersion($key));
}

public function testBuildOnCachedVersion(): void
Expand All @@ -146,13 +146,13 @@ public function testBuildOnCachedVersion(): void

$this->assertInstanceOf('Graby\SiteConfig\SiteConfig', $config1);

$this->assertEquals($config1, $configBuilder->getCachedVersion('host.io'));
$this->assertEquals($config1, $configBuilder->getCachedVersion('host.io.merged'));
$this->assertSame($config1, $configBuilder->getCachedVersion('host.io'));
$this->assertSame($config1, $configBuilder->getCachedVersion('host.io.merged'));

$config2 = $configBuilder->buildForHost('host.io');

$this->assertInstanceOf('Graby\SiteConfig\SiteConfig', $config2);
$this->assertEquals($config1, $config2);
$this->assertSame($config1, $config2);
}

public function dataForBuild(): array
Expand Down Expand Up @@ -212,7 +212,7 @@ public function testBuildWithCachedVersion(): void
$res2 = $configBuilder->loadSiteConfig('fr.wikipedia.org');

$this->assertInstanceOf('Graby\SiteConfig\SiteConfig', $res);
$this->assertEquals($res, $res2, 'Config retrieve from cache');
$this->assertSame($res, $res2, 'Config retrieve from cache');
}

public function testLogMessage(): void
Expand Down

0 comments on commit d92a656

Please sign in to comment.