Skip to content

Commit b903855

Browse files
authored
Merge pull request #491 from Seldaek/php72
Bump requirement to PHP 7.2 and PHPStan level 8
2 parents 092ce6f + 0a703fe commit b903855

File tree

124 files changed

+843
-1477
lines changed

Some content is hidden

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

124 files changed

+843
-1477
lines changed

.github/workflows/continuous-integration.yml

+2-16
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,14 @@ jobs:
1717
strategy:
1818
matrix:
1919
php-version:
20-
- "5.3"
21-
- "5.4"
22-
- "5.5"
23-
- "5.6"
24-
- "7.0"
25-
- "7.1"
2620
- "7.2"
2721
- "7.3"
2822
- "7.4"
2923
- "8.0"
3024
- "8.1"
3125
dependencies: [locked]
3226
include:
33-
- php-version: "5.3"
27+
- php-version: "7.2"
3428
dependencies: lowest
3529
- php-version: "8.1"
3630
dependencies: lowest
@@ -61,16 +55,8 @@ jobs:
6155
if: "contains(matrix.dependencies, 'lowest')"
6256
run: "echo \"COMPOSER_FLAGS=$COMPOSER_FLAGS --prefer-lowest\" >> $GITHUB_ENV"
6357

64-
- name: "Upgrade phpunit-bridge if needed for php 8 lowest build"
65-
if: "contains(matrix.php-version, '8.')"
66-
run: |
67-
composer require symfony/phpunit-bridge:^5.3.3 --dev --no-update
68-
6958
- name: "Install latest dependencies"
70-
run: |
71-
# Remove PHPStan as it requires a newer PHP
72-
composer remove phpstan/phpstan phpstan/phpstan-phpunit --dev --no-update
73-
composer update ${{ env.COMPOSER_FLAGS }}
59+
run: "composer update ${{ env.COMPOSER_FLAGS }}"
7460

7561
- name: "Run tests"
7662
run: "vendor/bin/simple-phpunit --verbose"

.github/workflows/lint.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
strategy:
1414
matrix:
1515
php-version:
16-
- "5.3"
17-
- "8.0"
16+
- "7.2"
17+
- "latest"
1818

1919
steps:
2020
- name: "Checkout"

.github/workflows/phpstan.yml

+2-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@ jobs:
1717
strategy:
1818
matrix:
1919
php-version:
20-
# pinned to 7.4 because we need PHPUnit 7.5 which does not support PHP 8
21-
- "7.4"
20+
- "8.0"
2221

2322
steps:
2423
- name: "Checkout"
@@ -45,7 +44,6 @@ jobs:
4544
run: "composer update ${{ env.COMPOSER_FLAGS }}"
4645

4746
- name: Run PHPStan
48-
# Locked to phpunit 7.5 here as newer ones have void return types which break inheritance
4947
run: |
50-
composer require --dev phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}
48+
composer require --dev phpunit/phpunit:^8.5.18 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}
5149
vendor/bin/phpstan analyse

composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -96,18 +96,19 @@
9696
}
9797
},
9898
"require": {
99+
"php": "^7.2 || ^8.0",
99100
"composer-plugin-api": "^1.0 || ^2.0"
100101
},
101102
"require-dev": {
102103
"composer/composer": "1.6.* || ^2.0",
103104
"composer/semver": "^1 || ^3",
104-
"symfony/phpunit-bridge": "^4.2 || ^5",
105+
"symfony/phpunit-bridge": "^5.3",
105106
"phpstan/phpstan": "^0.12.55",
106-
"symfony/process": "^2.3",
107+
"symfony/process": "^5",
107108
"phpstan/phpstan-phpunit": "^0.12.16"
108109
},
109110
"scripts": {
110-
"test": "SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit",
111+
"test": "vendor/bin/simple-phpunit",
111112
"phpstan": "vendor/bin/phpstan analyse"
112113
}
113114
}

phpstan.neon.dist

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
parameters:
2-
level: 5
2+
level: 8
33
paths:
44
- src
55
- tests
66
excludes_analyse:
77
- tests/Composer/Installers/Test/PolyfillTestCase.php
8+
ignoreErrors:
9+
- '~Test::[a-zA-Z0-9]+Provider\(\) return type~'
810

911
includes:
1012
- vendor/phpstan/phpstan-phpunit/extension.neon

phpunit.xml.dist

+1-8
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,15 @@
88
convertWarningsToExceptions="true"
99
processIsolation="false"
1010
stopOnFailure="false"
11-
syntaxCheck="false"
1211
bootstrap="vendor/autoload.php"
1312
>
1413
<php>
15-
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
14+
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0"/>
1615
</php>
1716

1817
<testsuites>
1918
<testsuite name="Installers Test Suite">
2019
<directory>tests/Composer/Installers</directory>
2120
</testsuite>
2221
</testsuites>
23-
24-
<filter>
25-
<whitelist>
26-
<directory>src/Composer/Installers</directory>
27-
</whitelist>
28-
</filter>
2922
</phpunit>
+10-2
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,29 @@
11
<?php
2+
23
namespace Composer\Installers;
34

45
class AglInstaller extends BaseInstaller
56
{
7+
/** @var array<string, string> */
68
protected $locations = array(
79
'module' => 'More/{$name}/',
810
);
911

1012
/**
1113
* Format package name to CamelCase
1214
*/
13-
public function inflectPackageVars($vars)
15+
public function inflectPackageVars(array $vars): array
1416
{
15-
$vars['name'] = preg_replace_callback('/(?:^|_|-)(.?)/', function ($matches) {
17+
$name = preg_replace_callback('/(?:^|_|-)(.?)/', function ($matches) {
1618
return strtoupper($matches[1]);
1719
}, $vars['name']);
1820

21+
if (null === $name) {
22+
throw new \RuntimeException('Failed to run preg_replace_callback: '.preg_last_error());
23+
}
24+
25+
$vars['name'] = $name;
26+
1927
return $vars;
2028
}
2129
}

src/Composer/Installers/AimeosInstaller.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
namespace Composer\Installers;
34

45
class AimeosInstaller extends BaseInstaller
56
{
7+
/** @var array<string, string> */
68
protected $locations = array(
79
'extension' => 'ext/{$name}/',
810
);

src/Composer/Installers/AnnotateCmsInstaller.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
namespace Composer\Installers;
34

45
class AnnotateCmsInstaller extends BaseInstaller
56
{
7+
/** @var array<string, string> */
68
protected $locations = array(
79
'module' => 'addons/modules/{$name}/',
810
'component' => 'addons/components/{$name}/',

src/Composer/Installers/AsgardInstaller.php

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
namespace Composer\Installers;
34

45
class AsgardInstaller extends BaseInstaller
56
{
7+
/** @var array<string, string> */
68
protected $locations = array(
79
'module' => 'Modules/{$name}/',
810
'theme' => 'Themes/{$name}/'
@@ -14,9 +16,8 @@ class AsgardInstaller extends BaseInstaller
1416
* For package type asgard-module, cut off a trailing '-plugin' if present.
1517
*
1618
* For package type asgard-theme, cut off a trailing '-theme' if present.
17-
*
1819
*/
19-
public function inflectPackageVars($vars)
20+
public function inflectPackageVars(array $vars): array
2021
{
2122
if ($vars['type'] === 'asgard-module') {
2223
return $this->inflectPluginVars($vars);
@@ -29,18 +30,26 @@ public function inflectPackageVars($vars)
2930
return $vars;
3031
}
3132

32-
protected function inflectPluginVars($vars)
33+
/**
34+
* @param array<string, string> $vars
35+
* @return array<string, string>
36+
*/
37+
protected function inflectPluginVars(array $vars): array
3338
{
34-
$vars['name'] = preg_replace('/-module$/', '', $vars['name']);
39+
$vars['name'] = $this->pregReplace('/-module$/', '', $vars['name']);
3540
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
3641
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));
3742

3843
return $vars;
3944
}
4045

41-
protected function inflectThemeVars($vars)
46+
/**
47+
* @param array<string, string> $vars
48+
* @return array<string, string>
49+
*/
50+
protected function inflectThemeVars(array $vars): array
4251
{
43-
$vars['name'] = preg_replace('/-theme$/', '', $vars['name']);
52+
$vars['name'] = $this->pregReplace('/-theme$/', '', $vars['name']);
4453
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
4554
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));
4655

src/Composer/Installers/AttogramInstaller.php

+2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
<?php
2+
23
namespace Composer\Installers;
34

45
class AttogramInstaller extends BaseInstaller
56
{
7+
/** @var array<string, string> */
68
protected $locations = array(
79
'module' => 'modules/{$name}/',
810
);

src/Composer/Installers/BaseInstaller.php

+28-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<?php
2+
23
namespace Composer\Installers;
34

45
use Composer\IO\IOInterface;
@@ -7,19 +8,19 @@
78

89
abstract class BaseInstaller
910
{
11+
/** @var array<string, string> */
1012
protected $locations = array();
13+
/** @var Composer */
1114
protected $composer;
15+
/** @var PackageInterface */
1216
protected $package;
17+
/** @var IOInterface */
1318
protected $io;
1419

1520
/**
1621
* Initializes base installer.
17-
*
18-
* @param PackageInterface $package
19-
* @param Composer $composer
20-
* @param IOInterface $io
2122
*/
22-
public function __construct(PackageInterface $package = null, Composer $composer = null, IOInterface $io = null)
23+
public function __construct(PackageInterface $package, Composer $composer, IOInterface $io)
2324
{
2425
$this->composer = $composer;
2526
$this->package = $package;
@@ -28,12 +29,8 @@ public function __construct(PackageInterface $package = null, Composer $composer
2829

2930
/**
3031
* Return the install path based on package type.
31-
*
32-
* @param PackageInterface $package
33-
* @param string $frameworkType
34-
* @return string
3532
*/
36-
public function getInstallPath(PackageInterface $package, $frameworkType = '')
33+
public function getInstallPath(PackageInterface $package, string $frameworkType = ''): string
3734
{
3835
$type = $this->package->getType();
3936

@@ -52,18 +49,16 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '')
5249
$availableVars['name'] = $extra['installer-name'];
5350
}
5451

55-
if ($this->composer->getPackage()) {
56-
$extra = $this->composer->getPackage()->getExtra();
57-
if (!empty($extra['installer-paths'])) {
58-
$customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor);
59-
if ($customPath !== false) {
60-
return $this->templatePath($customPath, $availableVars);
61-
}
52+
$extra = $this->composer->getPackage()->getExtra();
53+
if (!empty($extra['installer-paths'])) {
54+
$customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor);
55+
if ($customPath !== false) {
56+
return $this->templatePath($customPath, $availableVars);
6257
}
6358
}
6459

6560
$packageType = substr($type, strlen($frameworkType) + 1);
66-
$locations = $this->getLocations();
61+
$locations = $this->getLocations($frameworkType);
6762
if (!isset($locations[$packageType])) {
6863
throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type));
6964
}
@@ -77,7 +72,7 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '')
7772
* @param array<string, string> $vars This will normally receive array{name: string, vendor: string, type: string}
7873
* @return array<string, string>
7974
*/
80-
public function inflectPackageVars($vars)
75+
public function inflectPackageVars(array $vars): array
8176
{
8277
return $vars;
8378
}
@@ -87,19 +82,17 @@ public function inflectPackageVars($vars)
8782
*
8883
* @return array<string, string> map of package types => install path
8984
*/
90-
public function getLocations()
85+
public function getLocations(string $frameworkType)
9186
{
9287
return $this->locations;
9388
}
9489

9590
/**
9691
* Replace vars in a path
9792
*
98-
* @param string $path
9993
* @param array<string, string> $vars
100-
* @return string
10194
*/
102-
protected function templatePath($path, array $vars = array())
95+
protected function templatePath(string $path, array $vars = array()): string
10396
{
10497
if (strpos($path, '{') !== false) {
10598
extract($vars);
@@ -117,13 +110,10 @@ protected function templatePath($path, array $vars = array())
117110
/**
118111
* Search through a passed paths array for a custom install path.
119112
*
120-
* @param array $paths
121-
* @param string $name
122-
* @param string $type
123-
* @param string $vendor = NULL
113+
* @param array<string, string[]|string> $paths
124114
* @return string|false
125115
*/
126-
protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = NULL)
116+
protected function mapCustomInstallPaths(array $paths, string $name, string $type, ?string $vendor = null)
127117
{
128118
foreach ($paths as $path => $names) {
129119
$names = (array) $names;
@@ -134,4 +124,14 @@ protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = N
134124

135125
return false;
136126
}
127+
128+
protected function pregReplace(string $pattern, string $replacement, string $subject): string
129+
{
130+
$result = preg_replace($pattern, $replacement, $subject);
131+
if (null === $result) {
132+
throw new \RuntimeException('Failed to run preg_replace with '.$pattern.': '.preg_last_error());
133+
}
134+
135+
return $result;
136+
}
137137
}

0 commit comments

Comments
 (0)