Skip to content

Commit edc68cf

Browse files
authored
Merge pull request #19 from phpcr/cleanup-build
cleanup build matrix and adjust to semantic branch naming
2 parents 3595192 + 999ee7b commit edc68cf

21 files changed

+157
-170
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

.github/workflows/test-application.yaml

+8-4
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ on:
44
pull_request:
55
push:
66
branches:
7-
- 'master'
7+
- '[0-9]+.x'
8+
- '[0-9]+.[0-9]+'
9+
- '[0-9]+.[0-9]+.x'
810

911
jobs:
1012
test:
1113
name: 'PHP ${{ matrix.php-version }} ${{ matrix.dependencies }}'
12-
runs-on: ubuntu-20.04
14+
runs-on: ubuntu-latest
1315
env:
1416
SYMFONY_DEPRECATIONS_HELPER: weak
1517

@@ -23,10 +25,12 @@ jobs:
2325
- php-version: '7.4'
2426
- php-version: '8.0'
2527
- php-version: '8.1'
28+
- php-version: '8.2'
29+
- php-version: '8.3'
2630

2731
steps:
2832
- name: Checkout project
29-
uses: actions/checkout@v2
33+
uses: actions/checkout@v4
3034

3135
- name: Install and configure PHP
3236
uses: shivammathur/setup-php@v2
@@ -35,7 +39,7 @@ jobs:
3539
tools: 'composer:v2'
3640

3741
- name: Install dependencies with Composer
38-
uses: ramsey/composer-install@v1
42+
uses: ramsey/composer-install@v3
3943
with:
4044
dependency-versions: ${{ matrix.dependencies }}
4145
composer-options: --prefer-dist

.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.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ PHPCR Migrations
22
================
33

44
[![Build
5-
Status](https://travis-ci.org/phpcr/phpcr-migrations.svg?branch=master)](https://travis-ci.org/phpcr/phpcr-migrations)
5+
Status](https://github.com/phpcr/phpcr-migrations/actions/workflows/test-application.yaml/badge.svg)](https://github.com/phpcr/phpcr-migrations/actions/workflows/test-application.yaml)
66

77
Migrations library for PHPCR influenced by [Doctrine
88
migrations](https://github.com/doctrine/migrations).

composer.json

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"require-dev": {
1818
"jackalope/jackalope-fs": "0.0.*",
1919
"handcraftedinthealps/zendsearch": "^2.0",
20-
"phpunit/phpunit": "^8.5 || ^9.4"
20+
"phpunit/phpunit": "^8.5 || ^9.4",
21+
"phpspec/prophecy": "^1.19"
2122
},
2223
"autoload": {
2324
"psr-4": {
@@ -28,8 +29,5 @@
2829
"psr-4": {
2930
"PHPCR\\Migrations\\Tests\\": "tests"
3031
}
31-
},
32-
"extra": {
33-
"branch-alias": {"dev-master": "1.x-dev" }
3432
}
3533
}

lib/Migrator.php

+15-22
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,
@@ -57,15 +57,14 @@ public function initialize()
5757
* If $to is 0 then all migrations will be reverted.
5858
* If $to is null then all migrations will be executed.
5959
*
60-
* @param string|null $to Version to run until
61-
* @param OutputInterface $output
60+
* @param string|int|bool|null $to Version to run until
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

+16-15
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class MigratorUtil
2424
*/
2525
public static function getClassNameFromFile($file)
2626
{
27-
$fp = fopen($file, 'r');
27+
$fp = fopen($file, 'rb');
2828

2929
$class = $namespace = $buffer = '';
3030
$i = 0;
@@ -35,40 +35,41 @@ 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);
42+
$tokensCount = count($tokens);
4243

43-
if (strpos($buffer, '{') === false) {
44+
if (false === strpos($buffer, '{')) {
4445
continue;
4546
}
4647

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] === ';') {
48+
for (; $i < $tokensCount; ++$i) {
49+
if (T_NAMESPACE === $tokens[$i][0]) {
50+
for ($j = $i + 1; $j < $tokensCount; ++$j) {
51+
if (T_STRING === $tokens[$j][0] || (\defined('T_NAME_QUALIFIED') && T_NAME_QUALIFIED === $tokens[$j][0])) {
52+
$namespace .= '\\'.$tokens[$j][1];
53+
} elseif ('{' === $tokens[$j] || ';' === $tokens[$j]) {
5354
break;
5455
}
5556
}
5657
}
5758

58-
if ($tokens[$i][0] === T_CLASS) {
59-
for ($j = $i + 1;$j < count($tokens);$j++) {
60-
if ($tokens[$j] === '{') {
59+
if (T_CLASS === $tokens[$i][0]) {
60+
for ($j = $i + 1; $j < $tokensCount; ++$j) {
61+
if ('{' === $tokens[$j]) {
6162
$class = $tokens[$i + 2][1];
6263
}
6364
}
6465
}
6566
}
66-
};
67+
}
6768

6869
if (!$class) {
69-
return;
70+
throw new \RuntimeException('Could not determine class for migration');
7071
}
7172

72-
return $namespace . '\\' . $class;
73+
return $namespace.'\\'.$class;
7374
}
7475
}

lib/VersionCollection.php

+8-15
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;
@@ -86,13 +86,13 @@ public function getLatestVersion()
8686
/**
8787
* Return the version after the given version.
8888
*
89-
* @param string $from
89+
* @param string|null $from
9090
*/
9191
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

@@ -105,8 +105,6 @@ public function getNextVersion($from)
105105
return $timestamp;
106106
}
107107
}
108-
109-
return;
110108
}
111109

112110
/**
@@ -126,9 +124,4 @@ public function getPreviousVersion($from)
126124

127125
return 0;
128126
}
129-
130-
private function normalizeTs($ts)
131-
{
132-
return $ts ? $ts : null;
133-
}
134127
}

0 commit comments

Comments
 (0)