Skip to content
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ jobs:
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
composer config version 1.9.0
composer remove --no-update --dev phan/phan friendsofphp/php-cs-fixer nette/utils phpmd/phpmd phpstan/phpstan squizlabs/php_codesniffer vimeo/psalm
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress ${{ matrix.php >= 8.1 && '--ignore-platform-req=php' || '' }}

- name: Prepare git config
Expand Down
4 changes: 3 additions & 1 deletion .github/workflows/phan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ jobs:

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress
run: |
composer remove --no-update --dev phpunit/phpunit friendsofphp/php-cs-fixer nette/utils phpmd/phpmd phpstan/phpstan squizlabs/php_codesniffer vimeo/psalm
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress

- name: Check style with Phan
run: composer run-script phan
8 changes: 5 additions & 3 deletions .github/workflows/phpcs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ jobs:
uses: actions/cache@v4
with:
path: vendor
key: style-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
key: cs-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
style-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-
cs-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress
run: |
composer remove --no-update --dev phpunit/phpunit phan/phan friendsofphp/php-cs-fixer nette/utils phpmd/phpmd phpstan/phpstan vimeo/psalm
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress

- name: Check style with PHPCS
run: composer run-script phpcs
8 changes: 5 additions & 3 deletions .github/workflows/phpcsf.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,15 @@ jobs:
uses: actions/cache@v4
with:
path: vendor
key: style-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
key: csf-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
style-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-
csf-${{ runner.os }}-${{ matrix.setup }}-${{ matrix.php }}-

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress
run: |
composer remove --no-update --dev phpunit/phpunit phan/phan nette/utils phpmd/phpmd phpstan/phpstan squizlabs/php_codesniffer vimeo/psalm
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress

- name: Check style with phpcsf
run: composer run-script phpcsf
4 changes: 3 additions & 1 deletion .github/workflows/phpmd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ jobs:

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
run: composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress
run: |
composer remove --no-update --dev phpunit/phpunit phan/phan friendsofphp/php-cs-fixer nette/utils phpstan/phpstan squizlabs/php_codesniffer vimeo/psalm
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress

- name: Check style with phpmd
run: composer run-script phpmd
5 changes: 2 additions & 3 deletions .github/workflows/psalm.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.2']
php: ['8.4']
setup: ['stable']

name: PHP ${{ matrix.php }} - ${{ matrix.setup }}
Expand All @@ -38,9 +38,8 @@ jobs:

- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
# tests/use-fork.php because of https://github.com/vimeo/psalm/issues/8957
run: |
php tests/use-fork.php vimeo/psalm 5.14.2 https://github.com/kylekatarnls/psalm.git fix/datetime-inheritance-5.x
composer remove --no-update --dev phan/phan phpunit/phpunit friendsofphp/php-cs-fixer nette/utils phpmd/phpmd phpstan/phpstan squizlabs/php_codesniffer
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress

- name: Check style with psalm
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ jobs:
if: steps.composer-cache.outputs.cache-hit != 'true'
run: |
composer config version 1.9.0
composer remove --no-update --dev phan/phan friendsofphp/php-cs-fixer nette/utils phpmd/phpmd phpstan/phpstan squizlabs/php_codesniffer vimeo/psalm
composer update --prefer-dist ${{ matrix.setup != 'next' && format('--prefer-{0}', matrix.setup) || '' }} --no-progress ${{ matrix.php >= 8.1 && '--ignore-platform-req=php' || '' }} --no-interaction

- name: Prepare git config
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.15.0 || ^3.23.0",
"nette/utils": "^3.2.10",
"nette/utils": "^3.2.10 || ^4.1.3",
"phan/phan": "^3.2.10 || ^5.4.2",
"phpunit/phpunit": "^8.5.52 || ^9.6.34",
"phpmd/phpmd": "^2.13.0",
"phpstan/phpstan": "^0.11.15 || ^1.10.29",
"squizlabs/php_codesniffer": "^3.7.2",
"vimeo/psalm": "^4.30.0 || ^5.14.1"
"vimeo/psalm": "^4.30.0 || ^5.14.1 || ^6.15.1"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />

<ClassMustBeFinal errorLevel="info" />
<MissingOverrideAttribute errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
Expand Down
15 changes: 11 additions & 4 deletions src/Phug/Split/Command/Analyze.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Phug\Split\Command;

use Phug\Split;
use Phug\Split\UnableToListDirectoryItems;
use SimpleCli\SimpleCli;
use Traversable;

Expand Down Expand Up @@ -66,7 +67,7 @@ protected function calculatePackagesTree(Split $cli): bool
return $cli->error('Root project directory should contains a '.$this->composerFile.' file.');
}

$data = (array) json_decode(file_get_contents($this->composerFile), true);
$data = (array) json_decode((string) file_get_contents($this->composerFile), true);
$vendorDirectory = ($data['config'] ?? [])['vendor-dir'] ?? 'vendor';

$cli->writeLine((string) $data['name']);
Expand All @@ -93,7 +94,7 @@ protected function getPackages(): iterable

protected function dumpPackagesTree(Split $cli, iterable $packages, int $level = 0): bool
{
$count = is_countable($packages) ? count($packages) : INF;
$count = is_countable($packages) ? count($packages) : 0;

foreach ($packages as $index => $package) {
$symbol = $index === $count - 1 ? '└' : '├';
Expand All @@ -106,7 +107,13 @@ protected function dumpPackagesTree(Split $cli, iterable $packages, int $level =

protected function mapDirectories(string $directory, callable $callback): iterable
{
foreach (scandir($directory) as $element) {
$elements = scandir($directory);

if ($elements === false) {
throw new UnableToListDirectoryItems($directory);
}

foreach ($elements as $element) {
if (substr($element, 0, 1) === '.') {
continue;
}
Expand Down Expand Up @@ -141,7 +148,7 @@ protected function scanDirectories(string $directory): iterable
$composerPath = $directory.DIRECTORY_SEPARATOR.$this->composerFile;

if (file_exists($composerPath)) {
$data = json_decode(file_get_contents($composerPath), true);
$data = json_decode((string) file_get_contents($composerPath), true);
$mainPackage = $this->getPackage($directory, $data);
}

Expand Down
16 changes: 11 additions & 5 deletions src/Phug/Split/Command/CommandBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ protected function gitEscape(string $value): string
* @param array $options CLI git command options
* @param string|null $redirect redirection suffix (like '2>&1')
*
* @psalm-param truthy-string|null $redirect
*
* @return string
*
* @psalm-suppress UndefinedThisPropertyFetch RiskyTruthyFalsyComparison
* @psalm-suppress UndefinedThisPropertyFetch
*/
protected function getGitCommand(string $command, array $options = [], string $redirect = null): string
protected function getGitCommand(string $command, array $options = [], ?string $redirect = null): string
{
foreach ($options as $name => $value) {
$command .= ' --'.$name.'='.$this->gitEscape($value);
Expand All @@ -71,13 +73,15 @@ protected function getGitCommand(string $command, array $options = [], string $r
* @param array $options CLI git command options
* @param string|null $redirect redirection suffix (like '2>&1')
*
* @return string|null
* @psalm-param truthy-string|null $redirect
*
* @return string
*/
protected function git(string $command, array $options = [], string $redirect = null): ?string
protected function git(string $command, array $options = [], ?string $redirect = null): string
{
$command = $this->getGitCommand($command, $options, $redirect);

return shell_exec($command);
return (string) shell_exec($command);
}

/**
Expand Down Expand Up @@ -118,6 +122,8 @@ protected function last(string $directory = ''): Commit
*
* @return string|null
*
* @psalm-return truthy-string|null
*
* @psalm-suppress UndefinedThisPropertyFetch
*/
protected function getCurrentLinkedCommitHash(): ?string
Expand Down
5 changes: 4 additions & 1 deletion src/Phug/Split/Command/Copy.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ class Copy extends CommandBase
* @throws Exception
*
* @return bool
*
* @SuppressWarnings(PHPMD.ErrorControlOperator)
*/
public function run(SimpleCli $cli): bool
{
Expand All @@ -65,7 +67,8 @@ public function run(SimpleCli $cli): bool
return $cli->error('Last commit must be linked to a mono-repository commit.');
}

$destination = realpath($this->destination);
/** @psalm-var truthy-string|false $destination */
$destination = @realpath($this->destination);

if (!$destination) {
return $cli->error('Destination directory "'.$this->destination.'" does not seem to exist.');
Expand Down
13 changes: 8 additions & 5 deletions src/Phug/Split/Command/Dist.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,23 @@ protected function distribute(Split $cli): bool
$this->remove($this->output);
$cli->chdir($this->directory);
@mkdir($this->output, 0777, true);
$this->output = @realpath($this->output);
/** @psalm-var truthy-string|false $output */
$output = @realpath($this->output);

if (!$this->output) {
if (!$output) {
return $cli->error('Unable to create output directory.');
}

if (!preg_match('/^\* (.+)$/m', (string) $this->git('branch', [], '2>&1') ?: '', $branch)) {
$this->output = $output;

if (!preg_match('/^\* (.+)$/m', $this->git('branch', [], '2>&1') ?: '', $branch)) {
return $cli->error('You must be on a branch in a git repository to run this command.');
}

$branch = $branch[1];

if (substr($branch, 0, 18) === '(HEAD detached at ') {
$branch = trim(explode("\n", (string) $this->git('describe --contains --all HEAD', [], '2>&1') ?: '')[0]);
$branch = trim(explode("\n", $this->git('describe --contains --all HEAD', [], '2>&1') ?: '')[0]);
}

foreach ($this->getPackages() as $package) {
Expand All @@ -103,7 +106,7 @@ protected function distributePackage(Split $cli, array $package, string $branch)

$name = (string) $package['name'];

$data = (array) json_decode(file_get_contents(strtr($this->api, ['%s' => $name])), true);
$data = (array) json_decode((string) file_get_contents(strtr($this->api, ['%s' => $name])), true);
$config = $data['packages'][$name] ?? [];
$config = $config['dev-master'] ?? next($config);

Expand Down
8 changes: 4 additions & 4 deletions src/Phug/Split/Command/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ class Update extends Dist
protected function getPackage(string $directory, array $data): array
{
return [
'name' => $data['name'],
'directory' => realpath($directory),
'name' => (string) $data['name'],
'directory' => (string) realpath($directory),
'children' => [],
];
}
Expand Down Expand Up @@ -184,7 +184,7 @@ protected function cherryPickCommit(

if (!$this->noPush) {
$name = $package['name'];
$push = (string) $this->git("push origin $branch", [], '2>&1');
$push = $this->git("push origin $branch", [], '2>&1');
$cli->writeLine("Pushing $name\n".$push, strpos($push, 'error:') === false ? 'light_cyan' : 'red');
}

Expand Down Expand Up @@ -215,7 +215,7 @@ protected function distributePackage(Split $cli, array $package, string $branch)
}

$hash = $this->getCurrentLinkedCommitHash();
$distributionDirectory = getcwd();
$distributionDirectory = (string) getcwd();
$sourceDirectory = $package['directory'];

$cli->chdir($sourceDirectory);
Expand Down
6 changes: 5 additions & 1 deletion src/Phug/Split/Git/Commit.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public static function fromGitLogString(string $log): self
new Author(trim($matches['commitName']), trim($matches['commitEmail'])),
new Date($matches['commitDate']),
),
preg_replace('/^ {4}/m', '', trim($matches['message'])),
(string) preg_replace('/^ {4}/m', '', trim($matches['message'])),
);
}

Expand Down Expand Up @@ -126,6 +126,10 @@ public function getMessage(): string
* @param non-empty-string $regExp
*
* @return string|null
*
* @psalm-return truthy-string|null
*
* @psalm-suppress LessSpecificReturnStatement, MoreSpecificReturnType
*/
public function findInMessage(string $regExp): ?string
{
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Split/Git/EmptyLogList.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class EmptyLogList extends InvalidArgumentException
{
public function __construct(int $code = 0, Throwable $previous = null)
public function __construct(int $code = 0, ?Throwable $previous = null)
{
parent::__construct('Log list should contain at least one commit.', $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Split/Git/ImmutableLogException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class ImmutableLogException extends InvalidArgumentException
{
public function __construct(int $code = 0, Throwable $previous = null)
public function __construct(int $code = 0, ?Throwable $previous = null)
{
parent::__construct(
'Log instance is immutable, create a new instance new Log($commits) with a new list of commits',
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Split/Git/InvalidGitLogStringException.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class InvalidGitLogStringException extends InvalidArgumentException
{
public function __construct(string $log = '', int $code = 0, Throwable $previous = null)
public function __construct(string $log = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct("Invalid git log string: $log", $code, $previous);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Split/Git/InvalidGitLogUnit.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

class InvalidGitLogUnit extends InvalidArgumentException
{
public function __construct(string $unit = '', int $code = 0, Throwable $previous = null)
public function __construct(string $unit = '', int $code = 0, ?Throwable $previous = null)
{
parent::__construct("Invalid git log unit: $unit, ".Commit::class.' expected', $code, $previous);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Phug/Split/Git/Log.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,13 @@ public static function fromGitLogString(string $log): self
{
$commitLogs = preg_split('/[\n\r](?=commit )/', $log);

return new self(array_map(static function (string $commitLog) {
return new self($commitLogs === false ? [] : array_map(static function (string $commitLog) {
return Commit::fromGitLogString($commitLog);
}, $commitLogs));
}

/**
* Whether a offset exists.
* Whether an offset exists.
*
* @link https://php.net/manual/en/arrayaccess.offsetexists.php
*
Expand Down
2 changes: 1 addition & 1 deletion src/Phug/Split/InvalidCli.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

class InvalidCli extends InvalidArgumentException
{
public function __construct(object $cli, int $code = 0, Throwable $previous = null)
public function __construct(object $cli, int $code = 0, ?Throwable $previous = null)
{
$class = get_class($cli);

Expand Down
14 changes: 14 additions & 0 deletions src/Phug/Split/UnableToListDirectoryItems.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Phug\Split;

use RuntimeException;
use Throwable;

class UnableToListDirectoryItems extends RuntimeException
{
public function __construct(string $directory, int $code = 0, ?Throwable $previous = null)
{
parent::__construct("Unable to list items of the directory '$directory'", $code, $previous);
}
}
Loading
Loading