Skip to content

Add PHP 8.4 compatibility #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 2 additions & 11 deletions src/ConfigResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,21 @@

class ConfigResolver
{
/** @var ProjectTypeResolver */
private $typeResolver;

/** @var string */
private $template = __DIR__ . '/../templates/config/%s.json';

/**
* Constructor.
*
* @param ProjectTypeResolver $typeResolver
* @param string $template
*/
public function __construct(
ProjectTypeResolver $typeResolver,
string $template = null
private readonly ProjectTypeResolver $typeResolver,
?string $template = null
) {
$this->typeResolver = $typeResolver;
$this->template = $template ?? $this->template;
}

/**
* Resolve config.
*
* @return array
*/
public function resolve(): array
{
Expand Down
4 changes: 2 additions & 2 deletions src/Factory/ProcessFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@

namespace Youwe\TestingSuite\Composer\Factory;

use Override;
use Symfony\Component\Process\Process;

class ProcessFactory implements ProcessFactoryInterface
{
/**
* Create a new Process instance.
*
* @param string $commandLine
*
* @return Process
*/
#[Override]
public function create(string $commandLine): Process
{
// See https://github.com/composer/composer/blob/1.10.17/src/Composer/Util/ProcessExecutor.php#L68:L72
Expand Down
2 changes: 0 additions & 2 deletions src/Factory/ProcessFactoryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ interface ProcessFactoryInterface
/**
* Create a new Process instance.
*
* @param string $commandLine
*
* @return Process
*/
public function create(string $commandLine): Process;
}
43 changes: 13 additions & 30 deletions src/Installer/ArchiveExcludeInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Youwe\TestingSuite\Composer\Installer;

use Override;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
Expand All @@ -21,17 +22,9 @@
*/
class ArchiveExcludeInstaller implements InstallerInterface
{
/** @var JsonFile */
private $file;
private readonly JsonFile $file;

/** @var MappingResolver */
private $resolver;

/** @var IOInterface */
private $io;

/** @var string */
private $destination;
private readonly string|bool $destination;

/** @var array */
private $defaults = [
Expand All @@ -47,51 +40,41 @@ class ArchiveExcludeInstaller implements InstallerInterface
/**
* Constructor.
*
* @param MappingResolver $resolver
* @param IOInterface $io
* @param JsonFile|null $file
* @param string $destination
* @param array|null $defaults
*/
public function __construct(
MappingResolver $resolver,
IOInterface $io,
JsonFile $file = null,
string $destination = null,
array $defaults = null
private readonly MappingResolver $resolver,
private readonly IOInterface $io,
?JsonFile $file = null,
?string $destination = null,
?array $defaults = null
) {
$this->resolver = $resolver;
$this->io = $io;
$this->file = $file ?? new JsonFile(Factory::getComposerFile());
$this->destination = $destination ?? getcwd();
$this->defaults = $defaults ?? $this->defaults;
}

/**
* Install.
*
* @return void
*/
#[Override]
public function install(): void
{
$definition = $this->file->read();
$excluded = $definition['archive']['exclude'] ?? [];

$excluded = array_map(
function (string $exclude): string {
return substr($exclude, 0, 1) !== '/'
? '/' . $exclude
: $exclude;
},
fn(string $exclude): string => str_starts_with($exclude, '/')
? $exclude
: '/' . $exclude,
$excluded
);

$files = array_merge(
$this->defaults,
array_map(
function (FileMappingInterface $mapping): string {
return '/' . $mapping->getRelativeDestination();
},
fn(FileMappingInterface $mapping): string => '/' . $mapping->getRelativeDestination(),
iterator_to_array(
$this->resolver->resolve()
)
Expand Down
16 changes: 5 additions & 11 deletions src/Installer/ConfigInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Youwe\TestingSuite\Composer\Installer;

use Override;
use Composer\Factory;
use Composer\IO\IOInterface;
use Composer\Json\JsonFile;
Expand All @@ -20,31 +21,24 @@
*/
class ConfigInstaller implements InstallerInterface
{
/** @var JsonFile */
private $file;

/** @var ConfigResolver */
private $resolver;
private readonly JsonFile $file;

/**
* Constructor.
*
* @param ConfigResolver $resolver
* @param JsonFile|null $file
*/
public function __construct(
ConfigResolver $resolver,
JsonFile $file = null
private readonly ConfigResolver $resolver,
?JsonFile $file = null
) {
$this->resolver = $resolver;
$this->file = $file ?? new JsonFile(Factory::getComposerFile());
}

/**
* Install.
*
* @return void
*/
#[Override]
public function install(): void
{
$definition = $this->file->read();
Expand Down
81 changes: 26 additions & 55 deletions src/Installer/FilesInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

namespace Youwe\TestingSuite\Composer\Installer;

use Override;
use Composer\IO\IOInterface;
use Youwe\Composer\FileInstaller as ComposerFileInstaller;
use Youwe\FileMapping\FileMappingInterface;
Expand All @@ -19,37 +20,17 @@
*/
class FilesInstaller implements InstallerInterface
{
/** @var MappingResolver */
private $mappingResolver;

/** @var ComposerFileInstaller */
private $fileInstaller;

/** @var IOInterface */
private $io;

/**
* Constructor.
*
* @param MappingResolver $mappingResolver
* @param ComposerFileInstaller $fileInstaller
* @param IOInterface $io
*/
public function __construct(
MappingResolver $mappingResolver,
ComposerFileInstaller $fileInstaller,
IOInterface $io
) {
$this->mappingResolver = $mappingResolver;
$this->fileInstaller = $fileInstaller;
$this->io = $io;
public function __construct(private readonly MappingResolver $mappingResolver, private readonly ComposerFileInstaller $fileInstaller, private readonly IOInterface $io)
{
}

/**
* Install.
*
* @return void
*/
#[Override]
public function install(): void
{
foreach ($this->mappingResolver->resolve() as $mapping) {
Expand All @@ -70,11 +51,9 @@ public function install(): void
}

/**
* @param FileMappingInterface $unixFileMapping
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @return void
*/
private function resolveYouwePathing(FileMappingInterface $unixFileMapping): void
{
Expand Down Expand Up @@ -119,39 +98,31 @@ private function resolveYouwePathing(FileMappingInterface $unixFileMapping): voi
'./vendor/youwe/coding-standard-magento1/src/Magento1'
);
}
} else {
if ($name === "phpcs.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['./vendor/mediact/coding-standard/src/MediaCT'],
'./vendor/youwe/coding-standard/src/Global'
);
} elseif ($name === "phpmd.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
[
'./vendor/mediact/coding-standard/src/MediaCT/phpmd.xml',
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml'
],
'./vendor/youwe/coding-standard/src/Global/phpmd.xml'
);
} elseif ($name === "grumphp.yml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['vendor/mediact/testing-suite/config/default/grumphp.yml'],
'vendor/youwe/testing-suite/config/default/grumphp.yml'
);
}
} elseif ($name === "phpcs.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['./vendor/mediact/coding-standard/src/MediaCT'],
'./vendor/youwe/coding-standard/src/Global'
);
} elseif ($name === "phpmd.xml") {
$this->updatePath(
$unixFileMapping->getDestination(),
[
'./vendor/mediact/coding-standard/src/MediaCT/phpmd.xml',
'./vendor/youwe/coding-standard-magento2/src/Magento2/phpmd.xml'
],
'./vendor/youwe/coding-standard/src/Global/phpmd.xml'
);
} elseif ($name === "grumphp.yml") {
$this->updatePath(
$unixFileMapping->getDestination(),
['vendor/mediact/testing-suite/config/default/grumphp.yml'],
'vendor/youwe/testing-suite/config/default/grumphp.yml'
);
}
}

/**
* @param string $destination
* @param array $oldPaths
* @param string $newPath
*
* @return void
*/

private function updatePath(
string $destination,
array $oldPaths,
Expand Down
2 changes: 0 additions & 2 deletions src/Installer/InstallerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ interface InstallerInterface
{
/**
* Install.
*
* @return void
*/
public function install(): void;
}
Loading