Skip to content

Commit

Permalink
Merge pull request #491 from Seldaek/php72
Browse files Browse the repository at this point in the history
Bump requirement to PHP 7.2 and PHPStan level 8
  • Loading branch information
Seldaek authored Jul 23, 2021
2 parents 092ce6f + 0a703fe commit b903855
Show file tree
Hide file tree
Showing 124 changed files with 843 additions and 1,477 deletions.
18 changes: 2 additions & 16 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,14 @@ jobs:
strategy:
matrix:
php-version:
- "5.3"
- "5.4"
- "5.5"
- "5.6"
- "7.0"
- "7.1"
- "7.2"
- "7.3"
- "7.4"
- "8.0"
- "8.1"
dependencies: [locked]
include:
- php-version: "5.3"
- php-version: "7.2"
dependencies: lowest
- php-version: "8.1"
dependencies: lowest
Expand Down Expand Up @@ -61,16 +55,8 @@ jobs:
if: "contains(matrix.dependencies, 'lowest')"
run: "echo \"COMPOSER_FLAGS=$COMPOSER_FLAGS --prefer-lowest\" >> $GITHUB_ENV"

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

- name: "Run tests"
run: "vendor/bin/simple-phpunit --verbose"
4 changes: 2 additions & 2 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ jobs:
strategy:
matrix:
php-version:
- "5.3"
- "8.0"
- "7.2"
- "latest"

steps:
- name: "Checkout"
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ jobs:
strategy:
matrix:
php-version:
# pinned to 7.4 because we need PHPUnit 7.5 which does not support PHP 8
- "7.4"
- "8.0"

steps:
- name: "Checkout"
Expand All @@ -45,7 +44,6 @@ jobs:
run: "composer update ${{ env.COMPOSER_FLAGS }}"

- name: Run PHPStan
# Locked to phpunit 7.5 here as newer ones have void return types which break inheritance
run: |
composer require --dev phpunit/phpunit:^7.5.20 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}
composer require --dev phpunit/phpunit:^8.5.18 --with-all-dependencies ${{ env.COMPOSER_FLAGS }}
vendor/bin/phpstan analyse
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,18 +96,19 @@
}
},
"require": {
"php": "^7.2 || ^8.0",
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev": {
"composer/composer": "1.6.* || ^2.0",
"composer/semver": "^1 || ^3",
"symfony/phpunit-bridge": "^4.2 || ^5",
"symfony/phpunit-bridge": "^5.3",
"phpstan/phpstan": "^0.12.55",
"symfony/process": "^2.3",
"symfony/process": "^5",
"phpstan/phpstan-phpunit": "^0.12.16"
},
"scripts": {
"test": "SYMFONY_PHPUNIT_REMOVE_RETURN_TYPEHINT=1 vendor/bin/simple-phpunit",
"test": "vendor/bin/simple-phpunit",
"phpstan": "vendor/bin/phpstan analyse"
}
}
4 changes: 3 additions & 1 deletion phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
parameters:
level: 5
level: 8
paths:
- src
- tests
excludes_analyse:
- tests/Composer/Installers/Test/PolyfillTestCase.php
ignoreErrors:
- '~Test::[a-zA-Z0-9]+Provider\(\) return type~'

includes:
- vendor/phpstan/phpstan-phpunit/extension.neon
9 changes: 1 addition & 8 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,15 @@
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="vendor/autoload.php"
>
<php>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="weak"/>
<env name="SYMFONY_DEPRECATIONS_HELPER" value="max[direct]=0"/>
</php>

<testsuites>
<testsuite name="Installers Test Suite">
<directory>tests/Composer/Installers</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory>src/Composer/Installers</directory>
</whitelist>
</filter>
</phpunit>
12 changes: 10 additions & 2 deletions src/Composer/Installers/AglInstaller.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,29 @@
<?php

namespace Composer\Installers;

class AglInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'module' => 'More/{$name}/',
);

/**
* Format package name to CamelCase
*/
public function inflectPackageVars($vars)
public function inflectPackageVars(array $vars): array
{
$vars['name'] = preg_replace_callback('/(?:^|_|-)(.?)/', function ($matches) {
$name = preg_replace_callback('/(?:^|_|-)(.?)/', function ($matches) {
return strtoupper($matches[1]);
}, $vars['name']);

if (null === $name) {
throw new \RuntimeException('Failed to run preg_replace_callback: '.preg_last_error());
}

$vars['name'] = $name;

return $vars;
}
}
2 changes: 2 additions & 0 deletions src/Composer/Installers/AimeosInstaller.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Composer\Installers;

class AimeosInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'extension' => 'ext/{$name}/',
);
Expand Down
2 changes: 2 additions & 0 deletions src/Composer/Installers/AnnotateCmsInstaller.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Composer\Installers;

class AnnotateCmsInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'module' => 'addons/modules/{$name}/',
'component' => 'addons/components/{$name}/',
Expand Down
21 changes: 15 additions & 6 deletions src/Composer/Installers/AsgardInstaller.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Composer\Installers;

class AsgardInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'module' => 'Modules/{$name}/',
'theme' => 'Themes/{$name}/'
Expand All @@ -14,9 +16,8 @@ class AsgardInstaller extends BaseInstaller
* For package type asgard-module, cut off a trailing '-plugin' if present.
*
* For package type asgard-theme, cut off a trailing '-theme' if present.
*
*/
public function inflectPackageVars($vars)
public function inflectPackageVars(array $vars): array
{
if ($vars['type'] === 'asgard-module') {
return $this->inflectPluginVars($vars);
Expand All @@ -29,18 +30,26 @@ public function inflectPackageVars($vars)
return $vars;
}

protected function inflectPluginVars($vars)
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectPluginVars(array $vars): array
{
$vars['name'] = preg_replace('/-module$/', '', $vars['name']);
$vars['name'] = $this->pregReplace('/-module$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));

return $vars;
}

protected function inflectThemeVars($vars)
/**
* @param array<string, string> $vars
* @return array<string, string>
*/
protected function inflectThemeVars(array $vars): array
{
$vars['name'] = preg_replace('/-theme$/', '', $vars['name']);
$vars['name'] = $this->pregReplace('/-theme$/', '', $vars['name']);
$vars['name'] = str_replace(array('-', '_'), ' ', $vars['name']);
$vars['name'] = str_replace(' ', '', ucwords($vars['name']));

Expand Down
2 changes: 2 additions & 0 deletions src/Composer/Installers/AttogramInstaller.php
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?php

namespace Composer\Installers;

class AttogramInstaller extends BaseInstaller
{
/** @var array<string, string> */
protected $locations = array(
'module' => 'modules/{$name}/',
);
Expand Down
56 changes: 28 additions & 28 deletions src/Composer/Installers/BaseInstaller.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace Composer\Installers;

use Composer\IO\IOInterface;
Expand All @@ -7,19 +8,19 @@

abstract class BaseInstaller
{
/** @var array<string, string> */
protected $locations = array();
/** @var Composer */
protected $composer;
/** @var PackageInterface */
protected $package;
/** @var IOInterface */
protected $io;

/**
* Initializes base installer.
*
* @param PackageInterface $package
* @param Composer $composer
* @param IOInterface $io
*/
public function __construct(PackageInterface $package = null, Composer $composer = null, IOInterface $io = null)
public function __construct(PackageInterface $package, Composer $composer, IOInterface $io)
{
$this->composer = $composer;
$this->package = $package;
Expand All @@ -28,12 +29,8 @@ public function __construct(PackageInterface $package = null, Composer $composer

/**
* Return the install path based on package type.
*
* @param PackageInterface $package
* @param string $frameworkType
* @return string
*/
public function getInstallPath(PackageInterface $package, $frameworkType = '')
public function getInstallPath(PackageInterface $package, string $frameworkType = ''): string
{
$type = $this->package->getType();

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

if ($this->composer->getPackage()) {
$extra = $this->composer->getPackage()->getExtra();
if (!empty($extra['installer-paths'])) {
$customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor);
if ($customPath !== false) {
return $this->templatePath($customPath, $availableVars);
}
$extra = $this->composer->getPackage()->getExtra();
if (!empty($extra['installer-paths'])) {
$customPath = $this->mapCustomInstallPaths($extra['installer-paths'], $prettyName, $type, $vendor);
if ($customPath !== false) {
return $this->templatePath($customPath, $availableVars);
}
}

$packageType = substr($type, strlen($frameworkType) + 1);
$locations = $this->getLocations();
$locations = $this->getLocations($frameworkType);
if (!isset($locations[$packageType])) {
throw new \InvalidArgumentException(sprintf('Package type "%s" is not supported', $type));
}
Expand All @@ -77,7 +72,7 @@ public function getInstallPath(PackageInterface $package, $frameworkType = '')
* @param array<string, string> $vars This will normally receive array{name: string, vendor: string, type: string}
* @return array<string, string>
*/
public function inflectPackageVars($vars)
public function inflectPackageVars(array $vars): array
{
return $vars;
}
Expand All @@ -87,19 +82,17 @@ public function inflectPackageVars($vars)
*
* @return array<string, string> map of package types => install path
*/
public function getLocations()
public function getLocations(string $frameworkType)
{
return $this->locations;
}

/**
* Replace vars in a path
*
* @param string $path
* @param array<string, string> $vars
* @return string
*/
protected function templatePath($path, array $vars = array())
protected function templatePath(string $path, array $vars = array()): string
{
if (strpos($path, '{') !== false) {
extract($vars);
Expand All @@ -117,13 +110,10 @@ protected function templatePath($path, array $vars = array())
/**
* Search through a passed paths array for a custom install path.
*
* @param array $paths
* @param string $name
* @param string $type
* @param string $vendor = NULL
* @param array<string, string[]|string> $paths
* @return string|false
*/
protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = NULL)
protected function mapCustomInstallPaths(array $paths, string $name, string $type, ?string $vendor = null)
{
foreach ($paths as $path => $names) {
$names = (array) $names;
Expand All @@ -134,4 +124,14 @@ protected function mapCustomInstallPaths(array $paths, $name, $type, $vendor = N

return false;
}

protected function pregReplace(string $pattern, string $replacement, string $subject): string
{
$result = preg_replace($pattern, $replacement, $subject);
if (null === $result) {
throw new \RuntimeException('Failed to run preg_replace with '.$pattern.': '.preg_last_error());
}

return $result;
}
}
Loading

0 comments on commit b903855

Please sign in to comment.