Skip to content

Commit

Permalink
Use shim package (#27)
Browse files Browse the repository at this point in the history
  • Loading branch information
kubawerlos authored Mar 18, 2022
1 parent d4c5212 commit ef86a17
Show file tree
Hide file tree
Showing 22 changed files with 91 additions and 66 deletions.
3 changes: 1 addition & 2 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/src/Builder/ export-ignore
/tests/ export-ignore
/dev/ export-ignore
/.* export-ignore
/phpunit.xml export-ignore

Expand Down
4 changes: 3 additions & 1 deletion .php-cs-fixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@
* the LICENSE file that was distributed with this source code.
*/

require_once __DIR__ . '/vendor/autoload.php';

return PhpCsFixerConfig\Factory::createForLibrary('kubawerlos/php-cs-fixer-config', 'Kuba Werłos', 2020)
->setUsingCache(false)
->setFinder(
PhpCsFixer\Finder::create()
->files()
->in(__DIR__ . '/dev')
->in(__DIR__ . '/src')
->in(__DIR__ . '/tests')
->append([__FILE__]),
);
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@
],
"require": {
"php": "^8.0",
"friendsofphp/php-cs-fixer": "^3.6.0",
"kubawerlos/php-cs-fixer-custom-fixers": "^3.8.0"
"kubawerlos/php-cs-fixer-custom-fixers": "^3.10.0",
"php-cs-fixer/shim": "^3.7.0"
},
"require-dev": {
"phpunit/phpunit": "^9.5.10"
"phpunit/phpunit": "^9.5.19"
},
"autoload": {
"psr-4": {
Expand All @@ -23,12 +23,12 @@
},
"autoload-dev": {
"psr-4": {
"Tests\\": "./tests"
"Dev\\": "./dev"
}
},
"scripts": {
"fix": [
"@php ./src/Builder/build.php",
"@php ./dev/build.php",
"php-cs-fixer fix --quiet"
],
"verify": [
Expand Down
8 changes: 4 additions & 4 deletions src/Builder/Builder.php → dev/Builder/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
* the LICENSE file that was distributed with this source code.
*/

namespace PhpCsFixerConfig\Builder;
namespace Dev\Builder;

use PhpCsFixerConfig\Builder\Modifier\LibraryRulesModifier;
use PhpCsFixerConfig\Builder\Modifier\ProjectRulesModifier;
use Dev\Builder\Modifier\LibraryRulesModifier;
use Dev\Builder\Modifier\ProjectRulesModifier;

/**
* @internal
Expand Down Expand Up @@ -47,7 +47,7 @@ private function dumpClass(string $name, Rules $rules): void
$array = \preg_replace('/\d+\s*=>/', '', $array);
$array = \str_replace("'__HEADER_PLACEHOLDER__'", '$this->header', $array);

$path = __DIR__ . '/../Rules/' . $name . '.php';
$path = __DIR__ . '/../../src/Rules/' . $name . '.php';

$content = \file_get_contents($path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace PhpCsFixerConfig\Builder\Modifier;
namespace Dev\Builder\Modifier;

use PhpCsFixerCustomFixers\Fixer\NoNullableBooleanTypeFixer;
use PhpCsFixerCustomFixers\Fixer\PhpdocOnlyAllowedAnnotationsFixer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace PhpCsFixerConfig\Builder\Modifier;
namespace Dev\Builder\Modifier;

use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace PhpCsFixerConfig\Builder\Modifier;
namespace Dev\Builder\Modifier;

use PhpCsFixerCustomFixers\Fixer\PhpdocOnlyAllowedAnnotationsFixer;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace PhpCsFixerConfig\Builder\Modifier;
namespace Dev\Builder\Modifier;

/**
* @internal
Expand All @@ -25,11 +25,13 @@ final class UnwantedRulesFilter
'group_import',
'linebreak_after_opening_tag',
'no_blank_lines_before_namespace',
'no_trailing_comma_in_singleline_function_call', // NoTrailingCommaInSinglelineFixer used
'not_operator_with_space',
'not_operator_with_successor_space',
'php_unit_size_class',
'phpdoc_summary',
'phpdoc_to_property_type',
'single_line_comment_spacing', // CommentSurroundedBySpacesFixer used
];

/**
Expand Down
11 changes: 7 additions & 4 deletions src/Builder/Rules.php → dev/Builder/Rules.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@
* the LICENSE file that was distributed with this source code.
*/

namespace PhpCsFixerConfig\Builder;
namespace Dev\Builder;

use Dev\Builder\Modifier\NonDefaultConfiguration;
use Dev\Builder\Modifier\UnwantedRulesFilter;
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\FixerFactory;
use PhpCsFixerCustomFixers\Fixers;

/**
* @internal
Expand All @@ -36,15 +39,15 @@ public function __construct()

\ksort($this->rules);

foreach (new \PhpCsFixerCustomFixers\Fixers() as $fixer) {
foreach (new Fixers() as $fixer) {
if ($fixer instanceof DeprecatedFixerInterface) {
continue;
}
$this->rules[$fixer->getName()] = true;
}

$this->apply(new Modifier\NonDefaultConfiguration());
$this->apply(new Modifier\UnwantedRulesFilter());
$this->apply(new NonDefaultConfiguration());
$this->apply(new UnwantedRulesFilter());
}

public function apply(callable $closure): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\AutoReview;
namespace Dev\Test\AutoReview;

use PhpCsFixerConfig\Factory;
use PHPUnit\Framework\TestCase;
Expand All @@ -27,7 +27,7 @@ public function testOnlyFactoryClassIsPublic(): void
{
$finder = Finder::create()
->files()
->in(__DIR__ . '/../../src')
->in(__DIR__ . '/../../../src')
->notName('build.php');

/** @var SplFileInfo $file */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Builder\Modifier;
namespace Dev\Test\Builder\Modifier;

use Dev\Builder\Modifier\NonDefaultConfiguration;
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerConfiguration\DeprecatedFixerOptionInterface;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixerConfig\Builder\Modifier\NonDefaultConfiguration;
use PhpCsFixerCustomFixers\Fixers;
use PHPUnit\Framework\TestCase;

/**
* @covers \PhpCsFixerConfig\Builder\Modifier\NonDefaultConfiguration
* @covers \Dev\Builder\Modifier\NonDefaultConfiguration
*
* @internal
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Builder\Modifier;
namespace Dev\Test\Builder\Modifier;

use Dev\Builder\Modifier\UnwantedRulesFilter;
use PhpCsFixer\Fixer\DeprecatedFixerInterface;
use PhpCsFixer\Fixer\FixerInterface;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixerConfig\Builder\Modifier\UnwantedRulesFilter;
use PhpCsFixerCustomFixers\Fixers;
use PHPUnit\Framework\TestCase;

/**
* @covers \PhpCsFixerConfig\Builder\Modifier\UnwantedRulesFilter
* @covers \Dev\Builder\Modifier\UnwantedRulesFilter
*
* @internal
*/
Expand Down
10 changes: 5 additions & 5 deletions tests/BuilderTest.php → dev/Test/BuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests;
namespace Dev;

use PhpCsFixerConfig\Builder\Modifier\NonDefaultConfiguration;
use PhpCsFixerConfig\Builder\Modifier\UnwantedRulesFilter;
use Dev\Builder\Modifier\NonDefaultConfiguration;
use Dev\Builder\Modifier\UnwantedRulesFilter;
use PHPUnit\Framework\TestCase;

/**
* @covers \PhpCsFixerConfig\Builder\Modifier\NonDefaultConfiguration
* @covers \PhpCsFixerConfig\Builder\Modifier\UnwantedRulesFilter
* @covers \Dev\Builder\Modifier\NonDefaultConfiguration
* @covers \Dev\Builder\Modifier\UnwantedRulesFilter
*
* @internal
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/FactoryTest.php → dev/Test/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests;
namespace Dev;

use PhpCsFixer\Config;
use PhpCsFixerConfig\Factory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Rules;
namespace Dev\Test\Rules;

use Dev\Builder\Modifier\LibraryRulesModifier;
use Dev\Builder\Rules;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixerConfig\Builder\Modifier\LibraryRulesModifier;
use PhpCsFixerConfig\Builder\Rules;
use PhpCsFixerConfig\Rules\LibraryRules;
use PhpCsFixerCustomFixers\Fixers;
use PHPUnit\Framework\TestCase;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
* the LICENSE file that was distributed with this source code.
*/

namespace Tests\Rules;
namespace Dev\Test\Rules;

use Dev\Builder\Modifier\ProjectRulesModifier;
use Dev\Builder\Rules;
use PhpCsFixer\FixerFactory;
use PhpCsFixer\RuleSet\RuleSet;
use PhpCsFixerConfig\Builder\Modifier\ProjectRulesModifier;
use PhpCsFixerConfig\Builder\Rules;
use PhpCsFixerConfig\Rules\ProjectRules;
use PhpCsFixerCustomFixers\Fixers;
use PHPUnit\Framework\TestCase;
Expand Down
19 changes: 19 additions & 0 deletions dev/autoload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php declare(strict_types=1);

/*
* This file is part of kubawerlos/php-cs-fixer-config.
*
* (c) 2020 Kuba Werłos
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

$phar = __DIR__ . '/../vendor/php-cs-fixer/shim/php-cs-fixer';

$pharLoaded = Phar::loadPhar($phar, 'php-cs-fixer.phar');
if (!$pharLoaded) {
exit(sprintf('Phar "%s" not loaded!' . PHP_EOL, $phar));
}

require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
18 changes: 18 additions & 0 deletions dev/build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php declare(strict_types=1);

/*
* This file is part of kubawerlos/php-cs-fixer-config.
*
* (c) 2020 Kuba Werłos
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

require __DIR__ . '/../vendor/autoload.php';
require __DIR__ . '/autoload.php';

$builder = new Dev\Builder\Builder();
$builder->build();

exec('php ' . __DIR__ . '/../vendor/bin/php-cs-fixer fix');
6 changes: 2 additions & 4 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

<phpunit xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:noNamespaceSchemaLocation='./vendor/phpunit/phpunit/phpunit.xsd'
bootstrap='dev/autoload.php'
cacheResult='false'
colors='true'
forceCoversAnnotation='true'
Expand All @@ -16,17 +17,14 @@

<testsuites>
<testsuite name='all'>
<directory>./tests/</directory>
<directory>./dev/Test/</directory>
</testsuite>
</testsuites>

<coverage>
<include>
<directory>./src/</directory>
</include>
<exclude>
<directory>./src/Builder/</directory>
</exclude>
<report>
<text outputFile='php://stdout' showOnlySummary='true' />
</report>
Expand Down
22 changes: 0 additions & 22 deletions src/Builder/build.php

This file was deleted.

3 changes: 3 additions & 0 deletions src/Rules/LibraryRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ public function getRules(): array
],
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_comma_in_singleline_function_call' => false,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_trailing_whitespace_in_string' => true,
Expand Down Expand Up @@ -310,6 +311,7 @@ public function getRules(): array
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'single_line_comment_spacing' => false,
'single_line_comment_style' => true,
'single_line_throw' => true,
'single_quote' => true,
Expand Down Expand Up @@ -403,6 +405,7 @@ public function getRules(): array
Fixer\PhpdocParamTypeFixer::name() => true,
Fixer\PhpdocSelfAccessorFixer::name() => true,
Fixer\PhpdocSingleLineVarFixer::name() => true,
Fixer\PhpdocTypesCommaSpacesFixer::name() => true,
Fixer\PhpdocTypesTrimFixer::name() => true,
Fixer\PhpdocVarAnnotationToAssertFixer::name() => true,
Fixer\PromotedConstructorPropertyFixer::name() => true,
Expand Down
Loading

0 comments on commit ef86a17

Please sign in to comment.