Skip to content

Commit afadea7

Browse files
author
Tomáš Votruba
authored
Merge pull request #10 from Symplify/make-code-sniffer-fixer-work
Make code sniffer fixer work
2 parents fba7cb7 + 66e0d4b commit afadea7

File tree

80 files changed

+763
-1721
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

80 files changed

+763
-1721
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: php
22

33
php:
4-
- 5.6
4+
- 7.1
55

66
matrix:
77
include:

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Use multiple coding standards with zero-knowledge of PHP_CodeSniffer
1+
# Use multiple coding standards with zero-knowledge of PHP_CodeSniffer nor PHP-CS-Fixer
22

33
[![Build Status](https://img.shields.io/travis/Symplify/MultiCodingStandard.svg?style=flat-square)](https://travis-ci.org/Symplify/MultiCodingStandard)
44
[![Quality Score](https://img.shields.io/scrutinizer/g/Symplify/MultiCodingStandard.svg?style=flat-square)](https://scrutinizer-ci.com/g/Symplify/MultiCodingStandard)
@@ -10,12 +10,11 @@
1010
## Install
1111

1212
```sh
13-
composer require symplify/multi-coding-standard
13+
composer require symplify/multi-coding-standard --dev
1414
```
1515

1616
## Usage
1717

1818
```sh
19-
vendor/bin/multi-cs check [directory]
20-
vendor/bin/multi-cs check src
19+
vendor/bin/multi-cs src
2120
```

bin/di-container.php

Lines changed: 0 additions & 23 deletions
This file was deleted.

bin/multi-cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#!/usr/bin/env php
22
<?php
33

4-
/*
5-
* This file is part of Symplify
6-
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
7-
*/
8-
94
require_once __DIR__.'/bootstrap.php';
105

11-
/** @var Nette\DI\Container $container */
12-
$container = require_once __DIR__.'/di-container.php';
6+
// 1. build DI container
7+
$containerFactory = new Symplify\MultiCodingStandard\DI\ContainerFactory();
8+
$container = $containerFactory->create();
9+
10+
// 2. get Console Application
11+
/** @var Symplify\MultiCodingStandard\Console\ConsoleApplication $application */
12+
$application = $container->getByType(Symplify\MultiCodingStandard\Console\ConsoleApplication::class);
1313

14-
/** @var Symplify\MultiCodingStandard\Console\Application $application */
15-
$application = $container->getByType(Symplify\MultiCodingStandard\Console\Application::class);
14+
// 3. run it!
15+
$application->setDefaultCommand('run', true);
1616
$application->run();

composer.json

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,23 @@
55
"authors": [
66
{ "name": "Tomáš Votruba", "homepage": "http://tomasvotruba.cz" }
77
],
8+
"require": {
9+
"php": "^7.0",
10+
"symplify/php7_codesniffer": "^0.6",
11+
"friendsofphp/php-cs-fixer": "^1.12",
12+
"squizlabs/php_codesniffer": "3.0.x-dev as 2.6",
13+
"symfony/console": "3.2.x-dev as 3.1",
14+
"symfony/dependency-injection": "^3.0",
15+
"symfony/process": "^3.0",
16+
"nette/di": "^2.4",
17+
"nette/bootstrap": "^2.4",
18+
"nette/utils": "^2.4",
19+
"tracy/tracy": "^2.4"
20+
},
21+
"require-dev": {
22+
"phpunit/phpunit": "^5.5",
23+
"symplify/coding-standard": "~1.0"
24+
},
825
"autoload": {
926
"psr-4": {
1027
"Symplify\\MultiCodingStandard\\": "src"
@@ -15,21 +32,5 @@
1532
"Symplify\\MultiCodingStandard\\Tests\\": "tests"
1633
}
1734
},
18-
"require": {
19-
"php": "^5.6|^7.0",
20-
"symfony/console": "^2.8|^3.0",
21-
"symfony/dependency-injection": "^2.8|^3.0",
22-
"symfony/process": "^2.8|^3.0",
23-
"nette/di": "^2.3",
24-
"nette/bootstrap": "^2.3",
25-
"tracy/tracy": "^2.3",
26-
"squizlabs/php_codesniffer": "^2.6",
27-
"friendsofphp/php-cs-fixer": "^1.11",
28-
"nette/utils": "^2.3"
29-
},
30-
"require-dev": {
31-
"phpunit/phpunit": "^5.3",
32-
"symplify/coding-standard": "^0.2"
33-
},
3435
"bin": ["bin/multi-cs"]
3536
}

multi-cs.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22
"standards": [
33
"PSR2"
44
],
5-
"sniffs": [
6-
"SymplifyCodingStandard.Naming.AbstractClassName"
7-
],
8-
"exclude-sniffs": [
9-
"SymplifyCodingStandard.Naming.AbstractClassName"
10-
],
115
"fixer-levels": [
126
"psr1",
137
"psr2"

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@
1717
<directory suffix=".php">src</directory>
1818
</whitelist>
1919
</filter>
20-
</phpunit>
20+
</phpunit>

source/SomeAbstractClass.php

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/Application/Application.php

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Symplify
5+
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6+
*/
7+
8+
namespace Symplify\MultiCodingStandard\Application;
9+
10+
use Symplify\MultiCodingStandard\Application\Command\RunApplicationCommand;
11+
use Symplify\MultiCodingStandard\PhpCsFixer\Application\Application as PhpCsFixerApplication;
12+
use Symplify\MultiCodingStandard\PhpCsFixer\Application\Command\RunApplicationCommand as PhpCsFixerRunApplicationCommand;
13+
use Symplify\PHP7_CodeSniffer\Application\Application as Php7CodeSnifferApplication;
14+
use Symplify\PHP7_CodeSniffer\Application\Command\RunApplicationCommand as Php7CodeSnifferRunApplicationCommand;
15+
16+
final class Application
17+
{
18+
/**
19+
* @var Php7CodeSnifferApplication
20+
*/
21+
private $php7CodeSnifferApplication;
22+
23+
/**
24+
* @var PhpCsFixerApplication
25+
*/
26+
private $phpCsFixerApplication;
27+
28+
public function __construct(
29+
Php7CodeSnifferApplication $php7CodeSnifferApplication,
30+
PhpCsFixerApplication $phpCsFixerApplication
31+
) {
32+
$this->php7CodeSnifferApplication = $php7CodeSnifferApplication;
33+
$this->phpCsFixerApplication = $phpCsFixerApplication;
34+
}
35+
36+
public function runCommand(RunApplicationCommand $command)
37+
{
38+
$this->php7CodeSnifferApplication->runCommand(
39+
$this->createPhp7CodeSnifferRunApplicationCommand($command)
40+
);
41+
42+
$this->phpCsFixerApplication->runCommand(
43+
$this->createPhpCsFixerRunApplicationCommand($command)
44+
);
45+
}
46+
47+
private function createPhp7CodeSnifferRunApplicationCommand(RunApplicationCommand $command) : Php7CodeSnifferRunApplicationCommand
48+
{
49+
return new Php7CodeSnifferRunApplicationCommand(
50+
$command->getSource(),
51+
$command->getJsonConfiguration()['standards'] ?? [],
52+
$command->getJsonConfiguration()['sniffs'] ?? [],
53+
$command->getJsonConfiguration()['exclude-sniffs'] ?? [],
54+
$command->isFixer()
55+
);
56+
}
57+
58+
private function createPhpCsFixerRunApplicationCommand(RunApplicationCommand $command) : PhpCsFixerRunApplicationCommand
59+
{
60+
return new PhpCsFixerRunApplicationCommand(
61+
$command->getSource(),
62+
$command->getJsonConfiguration()['fixer-levels'] ?? [],
63+
$command->getJsonConfiguration()['fixers'] ?? [],
64+
$command->getJsonConfiguration()['exclude-fixers'] ?? [],
65+
$command->isFixer()
66+
);
67+
}
68+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?php
2+
3+
/*
4+
* This file is part of Symplify
5+
* Copyright (c) 2016 Tomas Votruba (http://tomasvotruba.cz).
6+
*/
7+
8+
namespace Symplify\MultiCodingStandard\Application\Command;
9+
10+
final class RunApplicationCommand
11+
{
12+
/**
13+
* @var array
14+
*/
15+
private $source;
16+
17+
/**
18+
* @var bool
19+
*/
20+
private $isFixer;
21+
22+
/**
23+
* @var array
24+
*/
25+
private $jsonConfiguration = [];
26+
27+
public function __construct(
28+
array $source,
29+
bool $isFixer,
30+
array $jsonConfiguration
31+
) {
32+
$this->source = $source;
33+
$this->isFixer = $isFixer;
34+
$this->jsonConfiguration = $jsonConfiguration;
35+
}
36+
37+
public function getSource() : array
38+
{
39+
return $this->source;
40+
}
41+
42+
public function getJsonConfiguration() : array
43+
{
44+
return $this->jsonConfiguration;
45+
}
46+
47+
public function isFixer() : bool
48+
{
49+
return $this->isFixer;
50+
}
51+
}

0 commit comments

Comments
 (0)