Skip to content

Commit 6ee26d7

Browse files
authored
Merge pull request #211 from mlocati/cs
Add PHP coding style rules and check PHP coding style
2 parents 997eea4 + 562c6a9 commit 6ee26d7

File tree

98 files changed

+2250
-1575
lines changed

Some content is hidden

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

98 files changed

+2250
-1575
lines changed

.atoum.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/**
3+
/*
44
* Pickle
55
*
66
*
@@ -39,12 +39,14 @@
3939
if (getenv('TRAVIS_PHP_VERSION') === '7.0') {
4040
$script
4141
->php('php -n -ddate.timezone=Europe/Paris')
42-
->noCodeCoverage();
42+
->noCodeCoverage()
43+
;
4344
} else {
4445
$script->noCodeCoverageForNamespaces('Composer');
4546
}
4647

4748
$script->addTestsFromDirectory(__DIR__ . '/tests/units');
4849
$runner
4950
->addExtension(new \Atoum\PraspelExtension\Manifest())
50-
->addExtension(new visibility\extension($script));
51+
->addExtension(new visibility\extension($script))
52+
;

.bootstrap.atoum.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/**
3+
/*
44
* Pickle
55
*
66
*

.github/workflows/test.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ jobs:
3636
fetch-depth: 0
3737
- name: Install Composer dependencies (including dev, preferring source)
3838
run: composer install --prefer-source --optimize-autoloader --ansi --no-interaction
39+
- name: Check coding style
40+
if: matrix.os == 'ubuntu-latest' && matrix.php-version == '7.2'
41+
run: ./vendor/bin/php-cs-fixer fix --path-mode=intersection --config=./.php_cs.dist --dry-run --using-cache=no --diff --diff-format=udiff --ansi --no-interaction .
3942
- name: Run Atoum
4043
run: php ./vendor/atoum/atoum/scripts/coverage.php --format xml --output clover.xml
4144
- name: Install Composer dependencies (excluding dev)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ vendor/
44
*.test
55
/clover.xml
66
/ocular.phar
7+
/.php_cs.cache

.php_cs.dist

Lines changed: 399 additions & 0 deletions
Large diffs are not rendered by default.

bin/pickle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ function includeIfExists($file)
1010
return file_exists($file) ? include $file : false;
1111
}
1212

13-
if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../autoload.php'))) {
14-
echo 'You must set up the project dependencies, run the following commands:'.PHP_EOL.
15-
'curl -sS https://getcomposer.org/installer | php'.PHP_EOL.
16-
'php composer.phar install'.PHP_EOL;
13+
if ((!$loader = includeIfExists(__DIR__ . '/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__ . '/../../../autoload.php'))) {
14+
echo 'You must set up the project dependencies, run the following commands:' . PHP_EOL
15+
. 'curl -sS https://getcomposer.org/installer | php' . PHP_EOL
16+
. 'php composer.phar install' . PHP_EOL;
1717

1818
exit(1);
1919
}
@@ -25,7 +25,7 @@ if (defined('PHP_WINDOWS_VERSION_MAJOR')) {
2525
| |_) | |/ __| |/ / |/ _ \
2626
| __/| | (__| <| | __/
2727
|_| |_|\___|_|\_\_|\___| ';
28-
} else {
28+
} else {
2929
$name = '
3030
██████╗ ██╗ ██████╗██╗ ██╗██╗ ███████╗
3131
██╔══██╗██║██╔════╝██║ ██╔╝██║ ██╔════╝

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
"atoum/praspel-extension": "~0.17",
3434
"atoum/visibility-extension": "~1.3",
3535
"behat/behat": "~3.6",
36-
"friendsofphp/php-cs-fixer": "^2.16",
36+
"friendsofphp/php-cs-fixer": "^2.18.1",
3737
"mlocati/composer-patcher": "^1.2.2",
3838
"symfony/process": "^5.0"
3939
},

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

features/bootstrap/FeatureContext.php

Lines changed: 58 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/**
3+
/*
44
* Pickle
55
*
66
*
@@ -33,6 +33,7 @@
3333
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3434
* POSSIBILITY OF SUCH DAMAGE.
3535
*/
36+
3637
use Behat\Behat\Context\SnippetAcceptingContext;
3738
use Behat\Gherkin\Node\PyStringNode;
3839
use Symfony\Component\Process\PhpExecutableFinder;
@@ -45,12 +46,16 @@
4546
*/
4647
class FeatureContext implements SnippetAcceptingContext
4748
{
48-
const PICKLE_BIN = 'bin/pickle';
49+
protected const PICKLE_BIN = 'bin/pickle';
4950

5051
private $assert;
52+
5153
private $php;
54+
5255
private $dir;
56+
5357
private $workingDir;
58+
5459
private $process;
5560

5661
public function __construct()
@@ -84,49 +89,40 @@ public function prepare()
8489
$this->php = $php;
8590
}
8691

87-
private function moveToNewPath($path)
88-
{
89-
$newWorkingDir = $this->workingDir .'/' . $path;
90-
91-
if (!file_exists($newWorkingDir)) {
92-
mkdir($newWorkingDir, 0777, true);
93-
}
94-
95-
$this->workingDir = $newWorkingDir;
96-
}
97-
9892
/**
9993
* @Given /^I am in the "([^"]*)" path$/
10094
*/
10195
public function iAmInThePath($path)
10296
{
10397
$this->moveToNewPath($path);
10498
}
105-
/* convert Convert package.xml to new format
106-
help Displays help for a command
107-
info Display information about a PECL extension
108-
install Install a php extension
109-
list Lists commands
110-
release Package a PECL extension for release
111-
validate Validate a PECL extension */
99+
100+
/* convert Convert package.xml to new format
101+
help Displays help for a command
102+
info Display information about a PECL extension
103+
install Install a php extension
104+
list Lists commands
105+
release Package a PECL extension for release
106+
validate Validate a PECL extension */
107+
112108
/**
113109
* @When /^I run "pickle(?: ((?:\"|[^"])*))?"$/
114110
*/
115111
public function iRunPickle($argumentsString = '')
116112
{
117-
$argumentsString = strtr($argumentsString, array('\'' => '"'));
118-
$arguments = explode(' ',$argumentsString);
113+
$argumentsString = strtr($argumentsString, ['\'' => '"']);
114+
$arguments = explode(' ', $argumentsString);
119115
$processArguments = [
120-
$this->php,
121-
__DIR__ . '/../../' . static::PICKLE_BIN,
122-
];
116+
$this->php,
117+
__DIR__ . '/../../' . static::PICKLE_BIN,
118+
];
123119

124120
$processArguments = array_merge($processArguments, $arguments);
125121
$processArguments[] = '--no-ansi';
126122
$this->process = new Process($processArguments);
127123

128124
$timeout = getenv('PICKLE_BEHAT_PROCESS_TIMEOUT');
129-
if (false !== $timeout) {
125+
if ($timeout !== false) {
130126
$this->process->setTimeout($timeout);
131127
}
132128

@@ -148,14 +144,14 @@ public function theOutputShouldContain(PyStringNode $text)
148144
*/
149145
public function itShouldFail($success)
150146
{
151-
if ('fail' === $success) {
152-
if (0 === $this->getExitCode()) {
147+
if ($success === 'fail') {
148+
if ($this->getExitCode() === 0) {
153149
echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput();
154150
}
155151

156152
$this->assert->integer($this->getExitCode())->isGreaterThan(0);
157153
} else {
158-
if (0 !== $this->getExitCode()) {
154+
if ($this->getExitCode() !== 0) {
159155
echo 'Actual output:' . PHP_EOL . PHP_EOL . $this->getOutput();
160156
}
161157

@@ -177,7 +173,7 @@ public function itShouldPassWith($success, PyStringNode $text)
177173
*/
178174
public function aFileNamedWith($filename, PyStringNode $content)
179175
{
180-
$content = strtr((string) $content, array("'''" => '"""'));
176+
$content = strtr((string) $content, ["'''" => '"""']);
181177
$this->createFile($this->workingDir . '/' . $filename, $content);
182178
}
183179

@@ -221,6 +217,36 @@ public function JsonfileShouldContain($path, PyStringNode $text)
221217
$this->assert->object($fileContent)->isEqualTo(json_decode($text));
222218
}
223219

220+
/**
221+
* @Then /^"([^"]*)" ((?:\d+\.?)+(?:RC\d*|beta\d*|alpha\d*)?) extension exists$/
222+
*/
223+
public function extensionExists($name, $version)
224+
{
225+
$url = 'https://pecl.php.net/get/' . $name . '/' . $version . '?uncompress=1';
226+
$file = $name . '-' . $version . '.tgz';
227+
$dir = $this->workingDir . '/' . $name . '-' . $version;
228+
229+
if (is_dir($dir) === false) {
230+
mkdir($dir, 0777, true);
231+
}
232+
$downloadFile = $dir . '/' . $file;
233+
file_put_contents($downloadFile, file_get_contents($url));
234+
$p = new PharData($downloadFile);
235+
$phar = $p->decompress('.tar');
236+
$phar->extractTo($dir);
237+
}
238+
239+
private function moveToNewPath($path)
240+
{
241+
$newWorkingDir = $this->workingDir . '/' . $path;
242+
243+
if (!file_exists($newWorkingDir)) {
244+
mkdir($newWorkingDir, 0777, true);
245+
}
246+
247+
$this->workingDir = $newWorkingDir;
248+
}
249+
224250
private function getExitCode()
225251
{
226252
return $this->process->getExitCode();
@@ -249,21 +275,19 @@ private function getOutput()
249275
$output = str_replace(PHP_EOL, "\n", $output);
250276
}
251277

252-
return trim(preg_replace("/ +$/m", '', $output));
278+
return trim(preg_replace('/ +$/m', '', $output));
253279
}
254280

255281
private function getExpectedOutput(PyStringNode $expectedText)
256282
{
257-
$text = strtr(
283+
return strtr(
258284
$expectedText,
259285
[
260286
'\'\'\'' => '"""',
261287
'%%TMP_DIR%%' => sys_get_temp_dir(),
262288
'%%TEST_DIR%%' => realpath($this->dir),
263289
]
264290
);
265-
266-
return $text;
267291
}
268292

269293
private static function clearDirectory($path)
@@ -283,23 +307,4 @@ private static function clearDirectory($path)
283307

284308
rmdir($path);
285309
}
286-
287-
/**
288-
* @Then /^"([^"]*)" ((?:\d+\.?)+(?:RC\d*|beta\d*|alpha\d*)?) extension exists$/
289-
*/
290-
public function extensionExists($name, $version)
291-
{
292-
$url = 'https://pecl.php.net/get/' . $name . '/' . $version . '?uncompress=1';
293-
$file = $name . '-' . $version . '.tgz';
294-
$dir = $this->workingDir . '/' . $name . '-' . $version;
295-
296-
if (is_dir($dir) === false) {
297-
mkdir($dir, 0777, true);
298-
}
299-
$downloadFile = $dir . '/' . $file;
300-
file_put_contents($downloadFile, file_get_contents($url));
301-
$p = new PharData($downloadFile);
302-
$phar = $p->decompress('.tar');
303-
$phar->extractTo($dir);
304-
}
305310
}

features/bootstrap/PharFeatureContext.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
/**
3+
/*
44
* Pickle
55
*
66
*
@@ -33,7 +33,8 @@
3333
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
3434
* POSSIBILITY OF SUCH DAMAGE.
3535
*/
36+
3637
class PharFeatureContext extends FeatureContext
3738
{
38-
const PICKLE_BIN = 'pickle.phar';
39+
protected const PICKLE_BIN = 'pickle.phar';
3940
}

0 commit comments

Comments
 (0)