Skip to content

Commit e7f92ca

Browse files
committed
php cs fixer
1 parent b3e5a2e commit e7f92ca

17 files changed

+124
-140
lines changed

.github/workflows/static.yaml

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: Static analysis
2+
on:
3+
push:
4+
branches:
5+
- '[0-9]+.x'
6+
- '[0-9]+.[0-9]+'
7+
- '[0-9]+.[0-9]+.x'
8+
pull_request:
9+
10+
jobs:
11+
phpstan:
12+
name: PHPStan
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout code
16+
uses: actions/checkout@v4
17+
18+
- name: PHPStan
19+
uses: docker://oskarstark/phpstan-ga
20+
env:
21+
REQUIRE_DEV: true
22+
with:
23+
args: analyze --no-progress
24+
25+
php-cs-fixer:
26+
name: PHP-CS-Fixer
27+
runs-on: ubuntu-latest
28+
steps:
29+
- uses: actions/checkout@v4
30+
- name: PHP-CS-Fixer
31+
uses: docker://oskarstark/php-cs-fixer-ga
32+
with:
33+
args: --dry-run

.gitignore

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
composer.lock
2-
vendor
3-
tests/data
4-
tests/migrations
5-
.phpunit.result.cache
1+
/.php-cs-fixer.cache
2+
/.phpunit.result.cache
3+
/composer.lock
4+
/phpunit.xml
5+
/tests/data
6+
/tests/migrations
7+
/vendor

.php-cs-fixer.dist.php

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
$finder = PhpCsFixer\Finder::create()
4+
->exclude('vendor')
5+
->in(__DIR__);
6+
$config = new PhpCsFixer\Config();
7+
8+
return $config->setFinder($finder)
9+
->setRules([
10+
'@Symfony' => true,
11+
'array_syntax' => ['syntax' => 'short'],
12+
]);

.php_cs

-29
This file was deleted.

lib/Migrator.php

+14-21
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ class Migrator
2020
private $session;
2121
private $versionCollection;
2222
private $versionStorage;
23-
private $actions = array(
23+
private $actions = [
2424
'up', 'down', 'top', 'bottom',
25-
);
25+
];
2626

2727
public function __construct(
2828
SessionInterface $session,
@@ -58,14 +58,13 @@ public function initialize()
5858
* If $to is null then all migrations will be executed.
5959
*
6060
* @param string|null $to Version to run until
61-
* @param OutputInterface $output
6261
*
6362
* @return VersionInterface[] Executed migrations
6463
*/
6564
public function migrate($to, OutputInterface $output)
6665
{
6766
if (false === $to) {
68-
return array();
67+
return [];
6968
}
7069

7170
$from = $this->versionStorage->getCurrentVersion();
@@ -76,17 +75,17 @@ public function migrate($to, OutputInterface $output)
7675
$versionsToExecute = $this->versionCollection->getVersions($from, $to, $direction);
7776

7877
if (!$versionsToExecute) {
79-
return array();
78+
return [];
8079
}
8180

8281
$position = 0;
83-
$output->writeln(sprintf('<comment>%s</comment> %d version(s):', ($direction == 'up' ? 'Upgrading' : 'Reverting'), count($versionsToExecute)));
82+
$output->writeln(sprintf('<comment>%s</comment> %d version(s):', 'up' == $direction ? 'Upgrading' : 'Reverting', count($versionsToExecute)));
8483
foreach ($versionsToExecute as $timestamp => $version) {
85-
$position++;
86-
$output->writeln(sprintf(' %s [<info>%d/%d</info>]: %s', $direction == 'up' ? '+' : '-', $position, count($versionsToExecute), $timestamp));
84+
++$position;
85+
$output->writeln(sprintf(' %s [<info>%d/%d</info>]: %s', 'up' == $direction ? '+' : '-', $position, count($versionsToExecute), $timestamp));
8786
$version->$direction($this->session);
8887

89-
if ($direction === 'down') {
88+
if ('down' === $direction) {
9089
$this->versionStorage->remove($timestamp);
9190
} else {
9291
$this->versionStorage->add($timestamp);
@@ -117,34 +116,28 @@ private function resolveTo($to, $from)
117116
$to = strtolower($to);
118117
}
119118

120-
if ($to === 'down') {
119+
if ('down' === $to) {
121120
$to = $this->versionCollection->getPreviousVersion($from);
122121
}
123122

124-
if ($to === 'up') {
123+
if ('up' === $to) {
125124
$to = $this->versionCollection->getNextVersion($from);
126125
}
127126

128-
if ($to === 'bottom') {
127+
if ('bottom' === $to) {
129128
$to = 0;
130129
}
131130

132-
if ($to === 'top' || null === $to) {
131+
if ('top' === $to || null === $to) {
133132
$to = $this->versionCollection->getLatestVersion();
134133
}
135134

136135
if (0 !== $to && false === strtotime($to)) {
137-
throw new MigratorException(sprintf(
138-
'Unknown migration action "%s". Known actions: "%s"',
139-
$to,
140-
implode('", "', $this->actions)
141-
));
136+
throw new MigratorException(sprintf('Unknown migration action "%s". Known actions: "%s"', $to, implode('", "', $this->actions)));
142137
}
143138

144139
if (0 !== $to && !$this->versionCollection->has($to)) {
145-
throw new MigratorException(sprintf(
146-
'Unknown version "%s"', $to
147-
));
140+
throw new MigratorException(sprintf('Unknown version "%s"', $to));
148141
}
149142

150143
return $to;

lib/MigratorUtil.php

+13-13
Original file line numberDiff line numberDiff line change
@@ -35,40 +35,40 @@ public static function getClassNameFromFile($file)
3535
}
3636

3737
// Read entire lines to prevent keyword truncation
38-
for ($line = 0; $line <= 20; $line++) {
38+
for ($line = 0; $line <= 20; ++$line) {
3939
$buffer .= fgets($fp);
4040
}
4141
$tokens = @token_get_all($buffer);
4242

43-
if (strpos($buffer, '{') === false) {
43+
if (false === strpos($buffer, '{')) {
4444
continue;
4545
}
4646

47-
for (;$i < count($tokens);$i++) {
48-
if ($tokens[$i][0] === T_NAMESPACE) {
49-
for ($j = $i + 1;$j < count($tokens); $j++) {
50-
if (\defined('T_NAME_QUALIFIED') && $tokens[$j][0] === T_NAME_QUALIFIED || $tokens[$j][0] === T_STRING) {
51-
$namespace .= '\\' . $tokens[$j][1];
52-
} elseif ($tokens[$j] === '{' || $tokens[$j] === ';') {
47+
for (; $i < count($tokens); ++$i) {
48+
if (T_NAMESPACE === $tokens[$i][0]) {
49+
for ($j = $i + 1; $j < count($tokens); ++$j) {
50+
if (\defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $tokens[$j][0] || T_STRING === $tokens[$j][0]) {
51+
$namespace .= '\\'.$tokens[$j][1];
52+
} elseif ('{' === $tokens[$j] || ';' === $tokens[$j]) {
5353
break;
5454
}
5555
}
5656
}
5757

58-
if ($tokens[$i][0] === T_CLASS) {
59-
for ($j = $i + 1;$j < count($tokens);$j++) {
60-
if ($tokens[$j] === '{') {
58+
if (T_CLASS === $tokens[$i][0]) {
59+
for ($j = $i + 1; $j < count($tokens); ++$j) {
60+
if ('{' === $tokens[$j]) {
6161
$class = $tokens[$i + 2][1];
6262
}
6363
}
6464
}
6565
}
66-
};
66+
}
6767

6868
if (!$class) {
6969
return;
7070
}
7171

72-
return $namespace . '\\' . $class;
72+
return $namespace.'\\'.$class;
7373
}
7474
}

lib/VersionCollection.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -34,25 +34,25 @@ public function getAllVersions()
3434
public function getVersions($from, $to)
3535
{
3636
$direction = $from > $to ? 'down' : 'up';
37-
$result = array();
37+
$result = [];
3838
$versions = $this->versions;
3939

4040
if ($from == $to) {
41-
return array();
41+
return [];
4242
}
4343

44-
if ($direction === 'up') {
44+
if ('up' === $direction) {
4545
ksort($versions, SORT_STRING);
4646
} else {
4747
krsort($versions, SORT_STRING);
4848
}
4949

50-
$found = $from === null ? true : false;
50+
$found = null === $from ? true : false;
5151
foreach ($versions as $timestamp => $version) {
5252
if ($timestamp == $from) {
5353
$found = true;
5454

55-
if ($direction == 'down') {
55+
if ('down' == $direction) {
5656
$result[$timestamp] = $version;
5757
}
5858

@@ -64,7 +64,7 @@ public function getVersions($from, $to)
6464
}
6565

6666
if ($timestamp == $to) {
67-
if ($direction == 'up') {
67+
if ('up' == $direction) {
6868
$result[$timestamp] = $version;
6969
}
7070
break;
@@ -92,7 +92,7 @@ public function getNextVersion($from)
9292
{
9393
$found = false;
9494
foreach (array_keys($this->versions) as $timestamp) {
95-
if ($from === null) {
95+
if (null === $from) {
9696
return $timestamp;
9797
}
9898

lib/VersionFinder.php

+3-8
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@ class VersionFinder
2222
public function __construct(array $paths)
2323
{
2424
if (empty($paths)) {
25-
throw new \RuntimeException(
26-
'No paths were provided to the version finder.'
27-
);
25+
throw new \RuntimeException('No paths were provided to the version finder.');
2826
}
2927
$this->paths = $paths;
3028
}
@@ -35,7 +33,7 @@ public function getCollection()
3533
return $this->collection;
3634
}
3735

38-
$versions = array();
36+
$versions = [];
3937
$finder = new Finder();
4038
$finder->name('/Version[0-9]{12}.php/');
4139
$finder->files();
@@ -52,10 +50,7 @@ public function getCollection()
5250
$version = new $classFqn();
5351

5452
if (!$version instanceof VersionInterface) {
55-
throw new MigratorException(sprintf(
56-
'Version class "%s" must implement VersionInterface',
57-
$className
58-
));
53+
throw new MigratorException(sprintf('Version class "%s" must implement VersionInterface', $className));
5954
}
6055

6156
$versionTimestamp = substr($versionFile->getBaseName(), 7, 12);

lib/VersionInterface.php

-4
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@ interface VersionInterface
2828
{
2929
/**
3030
* Migrate the repository up.
31-
*
32-
* @param SessionInterface $session
3331
*/
3432
public function up(SessionInterface $session);
3533

3634
/**
3735
* Migrate the system down.
38-
*
39-
* @param SessionInterface $session
4036
*/
4137
public function down(SessionInterface $session);
4238
}

lib/VersionStorage.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function init()
4242
[phpcrmig:versions] > nt:base
4343
+* (phpcrmig:version)
4444
EOT
45-
, true);
45+
, true);
4646
}
4747

4848
$rootNode = $this->session->getRootNode();
@@ -61,21 +61,21 @@ public function getPersistedVersions()
6161
$this->init();
6262

6363
$versionNodes = $this->storageNode->getNodes();
64-
$versions = array();
64+
$versions = [];
6565

6666
foreach ($versionNodes as $versionNode) {
67-
$versions[$versionNode->getName()] = array(
67+
$versions[$versionNode->getName()] = [
6868
'name' => $versionNode->getName(),
6969
'executed' => $versionNode->getPropertyValue('jcr:created'),
70-
);
70+
];
7171
}
7272

7373
return $versions;
7474
}
7575

7676
public function hasVersioningNode()
7777
{
78-
return $this->session->nodeExists('/' . $this->storageNodeName);
78+
return $this->session->nodeExists('/'.$this->storageNodeName);
7979
}
8080

8181
public function getCurrentVersion()

tests/BaseTestCase.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class BaseTestCase extends TestCase
2222

2323
public function initPhpcr()
2424
{
25-
$path = __DIR__ . '/data';
25+
$path = __DIR__.'/data';
2626
$sfFs = new Filesystem();
2727
$sfFs->remove($path);
2828
$factory = new RepositoryFactoryFilesystem();
29-
$repository = $factory->getRepository(array(
29+
$repository = $factory->getRepository([
3030
'path' => $path,
3131
'search.enabled' => false,
32-
));
32+
]);
3333
$credentials = new SimpleCredentials('admin', 'admin');
3434
$this->session = $repository->login($credentials);
3535
}

0 commit comments

Comments
 (0)