Skip to content

Commit

Permalink
release PHP 7.2 downgraded
Browse files Browse the repository at this point in the history
  • Loading branch information
actions-user committed Feb 23, 2024
1 parent d32bd7d commit 8aa33fe
Show file tree
Hide file tree
Showing 3,209 changed files with 310,239 additions and 6,069 deletions.
The diff you're trying to view is too large. We only load the first 3000 changed files.
9 changes: 0 additions & 9 deletions .editorconfig

This file was deleted.

4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/vendor
# we need the vendor
composer.lock

/.phpunit.cache
.phpunit.result.cache


# to keep local rector outside git repository
Expand Down
3 changes: 2 additions & 1 deletion bin/ecs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env php
<?php
<?php
namespace ECSPrefix202402;

require __DIR__ . '/ecs.php';
102 changes: 39 additions & 63 deletions bin/ecs.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,28 @@
<?php

declare(strict_types=1);
declare (strict_types=1);
namespace ECSPrefix202402;

// decoupled in own "*.php" file, so ECS, Rector and PHPStan works out of the box here

use PHP_CodeSniffer\Util\Tokens;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArgvInput;
use ECSPrefix202402\Symfony\Component\Console\Command\Command;
use ECSPrefix202402\Symfony\Component\Console\Input\ArgvInput;
use Symplify\EasyCodingStandard\Console\EasyCodingStandardConsoleApplication;
use Symplify\EasyCodingStandard\Console\Style\SymfonyStyleFactory;
use Symplify\EasyCodingStandard\DependencyInjection\EasyCodingStandardContainerFactory;

// performance boost
gc_disable();

define('__ECS_RUNNING__', true);

\gc_disable();
\define('__ECS_RUNNING__', \true);
# 1. autoload
$autoloadIncluder = new AutoloadIncluder();

if (file_exists(__DIR__ . '/../preload.php')) {
if (\file_exists(__DIR__ . '/../preload.php')) {
require_once __DIR__ . '/../preload.php';
}

$autoloadIncluder->includeCwdVendorAutoloadIfExists();
$autoloadIncluder->loadIfNotLoadedYet(__DIR__ . '/../vendor/scoper-autoload.php');
$autoloadIncluder->autoloadProjectAutoloaderFile('/../../autoload.php');
$autoloadIncluder->includeDependencyOrRepositoryVendorAutoloadIfExists();
$autoloadIncluder->includePhpCodeSnifferAutoload();

/**
* Inspired by https://github.com/rectorphp/rector/pull/2373/files#diff-0fc04a2bb7928cac4ae339d5a8bf67f3
*/
Expand All @@ -45,116 +39,98 @@ final class AutoloadIncluder
// monorepo
__DIR__ . '/../../../vendor',
];

/**
* @var string[]
*/
private array $alreadyLoadedAutoloadFiles = [];

public function includeCwdVendorAutoloadIfExists(): void
private $alreadyLoadedAutoloadFiles = [];
public function includeCwdVendorAutoloadIfExists() : void
{
$cwdVendorAutoload = getcwd() . '/vendor/autoload.php';
if (! is_file($cwdVendorAutoload)) {
$cwdVendorAutoload = \getcwd() . '/vendor/autoload.php';
if (!\is_file($cwdVendorAutoload)) {
return;
}
$this->loadIfNotLoadedYet($cwdVendorAutoload);
}

public function includeDependencyOrRepositoryVendorAutoloadIfExists(): void
public function includeDependencyOrRepositoryVendorAutoloadIfExists() : void
{
// ECS' vendor is already loaded
if (class_exists('Symplify\EasyCodingStandard\DependencyInjection\LazyContainerFactory')) {
if (\class_exists('Symplify\\EasyCodingStandard\\DependencyInjection\\LazyContainerFactory')) {
return;
}

$devVendorAutoload = __DIR__ . '/../vendor/autoload.php';
if (! is_file($devVendorAutoload)) {
if (!\is_file($devVendorAutoload)) {
return;
}

$this->loadIfNotLoadedYet($devVendorAutoload);
}

public function autoloadProjectAutoloaderFile(string $file): void
public function autoloadProjectAutoloaderFile(string $file) : void
{
$path = dirname(__DIR__) . $file;
if (! is_file($path)) {
$path = \dirname(__DIR__) . $file;
if (!\is_file($path)) {
return;
}
$this->loadIfNotLoadedYet($path);
}

public function includePhpCodeSnifferAutoload(): void
public function includePhpCodeSnifferAutoload() : void
{
// 1. autoload
foreach (self::POSSIBLE_AUTOLOAD_PATHS as $possibleAutoloadPath) {
$possiblePhpCodeSnifferAutoloadPath = $possibleAutoloadPath . '/squizlabs/php_codesniffer/autoload.php';
if (! is_file($possiblePhpCodeSnifferAutoloadPath)) {
if (!\is_file($possiblePhpCodeSnifferAutoloadPath)) {
continue;
}

require_once $possiblePhpCodeSnifferAutoloadPath;
}

// initialize token with INT type, otherwise php-cs-fixer and php-parser breaks
if (! defined('T_MATCH')) {
define('T_MATCH', 5000);
if (!\defined('T_MATCH')) {
\define('T_MATCH', 5000);
}

if (! defined('T_READONLY')) {
define('T_READONLY', 5010);
if (!\defined('T_READONLY')) {
\define('T_READONLY', 5010);
}

if (! defined('T_ENUM')) {
define('T_ENUM', 5015);
if (!\defined('T_ENUM')) {
\define('T_ENUM', 5015);
}

if (! defined('T_NULLSAFE_OBJECT_OPERATOR')) {
define('T_NULLSAFE_OBJECT_OPERATOR', 5020);
if (!\defined('T_NULLSAFE_OBJECT_OPERATOR')) {
\define('T_NULLSAFE_OBJECT_OPERATOR', 5020);
}

// for PHP_CodeSniffer
define('PHP_CODESNIFFER_CBF', false);
define('PHP_CODESNIFFER_VERBOSITY', 0);

\define('PHP_CODESNIFFER_CBF', \false);
\define('PHP_CODESNIFFER_VERBOSITY', 0);
new Tokens();
}

public function loadIfNotLoadedYet(string $file): void
public function loadIfNotLoadedYet(string $file) : void
{
if (! file_exists($file)) {
if (!\file_exists($file)) {
return;
}

if (in_array($file, $this->alreadyLoadedAutoloadFiles, true)) {
if (\in_array($file, $this->alreadyLoadedAutoloadFiles, \true)) {
return;
}

$realPath = realpath($file);
if (! is_string($realPath)) {
$realPath = \realpath($file);
if (!\is_string($realPath)) {
return;
}

$this->alreadyLoadedAutoloadFiles[] = $realPath;
require_once $file;
}
}

/**
* Inspired by https://github.com/rectorphp/rector/pull/2373/files#diff-0fc04a2bb7928cac4ae339d5a8bf67f3
*/
\class_alias('ECSPrefix202402\\AutoloadIncluder', 'AutoloadIncluder', \false);
try {
$input = new ArgvInput();
$ecsContainerFactory = new EasyCodingStandardContainerFactory();
$container = $ecsContainerFactory->createFromFromInput($input);
} catch (Throwable $throwable) {
} catch (\Throwable $throwable) {
$symfonyStyleFactory = new SymfonyStyleFactory();
$symfonyStyle = $symfonyStyleFactory->create();

$symfonyStyle->error($throwable->getMessage());
$symfonyStyle->writeln($throwable->getTraceAsString());
exit(Command::FAILURE);
}

/** @var EasyCodingStandardConsoleApplication $application */
$application = $container->get(EasyCodingStandardConsoleApplication::class);

$statusCode = $application->run();
exit($statusCode);
69 changes: 20 additions & 49 deletions bin/generate-php-cs-fixer-tests.php
Original file line number Diff line number Diff line change
@@ -1,77 +1,48 @@
<?php

declare(strict_types=1);
declare (strict_types=1);
namespace ECSPrefix202402;

use PhpCsFixer\RuleSet\RuleSets;

// this helper script generates the withPhpCsFixerSets() method for ECSConfigBuilder class

require __DIR__ . '/../vendor/autoload.php';

$setsDirectory = __DIR__ . '/../vendor/friendsofphp/php-cs-fixer/src/RuleSet/Sets/';

$setDefinitions = RuleSets::getSetDefinitions();

$setNames = [];
foreach ($setDefinitions as $setDefinition) {
$setNames[] = $setDefinition->getName();
}

// create withPhpCsFixerSets() method here
$classMethod = new \PhpParser\Node\Stmt\ClassMethod('withPhpCsFixerSets');
$classMethod->flags = \PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC;
$classMethod->returnType = new \PhpParser\Node\Name('self');

$classMethod = new \ECSPrefix202402\PhpParser\Node\Stmt\ClassMethod('withPhpCsFixerSets');
$classMethod->flags = \ECSPrefix202402\PhpParser\Node\Stmt\Class_::MODIFIER_PUBLIC;
$classMethod->returnType = new \ECSPrefix202402\PhpParser\Node\Name('self');
foreach ($setNames as $setName) {
// convert to PHP variable name
$paramName = ltrim( $setName, '@');

$paramName = \ltrim($setName, '@');
$paramName = lowercaseUntilFirstLower($paramName);
$paramName = str_replace(':r', 'R', $paramName);
$paramName = str_replace(['.', '-', '_'], '', $paramName);

$paramName = \str_replace(':r', 'R', $paramName);
$paramName = \str_replace(['.', '-', '_'], '', $paramName);
// lowercase only the first uppercase letters

$classMethod->params[] = new \PhpParser\Node\Param(
new \PhpParser\Node\Expr\Variable($paramName),
new \PhpParser\Node\Expr\ConstFetch(new \PhpParser\Node\Name('false')),
new \PhpParser\Node\Identifier('bool')
);

$dynamicSetsPropertyFetch = new \PhpParser\Node\Expr\PropertyFetch(new \PhpParser\Node\Expr\Variable('this'), 'dynamicSets');

$classMethod->stmts[] = new \PhpParser\Node\Stmt\If_(new \PhpParser\Node\Expr\Variable($paramName), [
'stmts' => [
new \PhpParser\Node\Stmt\Expression(new \PhpParser\Node\Expr\Assign(
new \PhpParser\Node\Expr\ArrayDimFetch($dynamicSetsPropertyFetch),
new \PhpParser\Node\Scalar\String_($setName)
))
]
]);
$classMethod->params[] = new \ECSPrefix202402\PhpParser\Node\Param(new \ECSPrefix202402\PhpParser\Node\Expr\Variable($paramName), new \ECSPrefix202402\PhpParser\Node\Expr\ConstFetch(new \ECSPrefix202402\PhpParser\Node\Name('false')), new \ECSPrefix202402\PhpParser\Node\Identifier('bool'));
$dynamicSetsPropertyFetch = new \ECSPrefix202402\PhpParser\Node\Expr\PropertyFetch(new \ECSPrefix202402\PhpParser\Node\Expr\Variable('this'), 'dynamicSets');
$classMethod->stmts[] = new \ECSPrefix202402\PhpParser\Node\Stmt\If_(new \ECSPrefix202402\PhpParser\Node\Expr\Variable($paramName), ['stmts' => [new \ECSPrefix202402\PhpParser\Node\Stmt\Expression(new \ECSPrefix202402\PhpParser\Node\Expr\Assign(new \ECSPrefix202402\PhpParser\Node\Expr\ArrayDimFetch($dynamicSetsPropertyFetch), new \ECSPrefix202402\PhpParser\Node\Scalar\String_($setName)))]]);
}


function lowercaseUntilFirstLower($input) {
function lowercaseUntilFirstLower($input)
{
$output = '';
$foundLower = false;

for ($i = 0; $i < strlen($input); $i++) {
$foundLower = \false;
for ($i = 0; $i < \strlen($input); $i++) {
$char = $input[$i];

if (!$foundLower && ctype_upper($char)) {
$output .= strtolower($char);
if (!$foundLower && \ctype_upper($char)) {
$output .= \strtolower($char);
} else {
$output .= $char;
$foundLower = true;
$foundLower = \true;
}
}

return $output;
}
// add dynamic set includes

$classMethod->stmts[] = new \PhpParser\Node\Stmt\Return_(new \PhpParser\Node\Expr\Variable('this'));


$printerStandard = new \PhpParser\PrettyPrinter\Standard();
$classMethod->stmts[] = new \ECSPrefix202402\PhpParser\Node\Stmt\Return_(new \ECSPrefix202402\PhpParser\Node\Expr\Variable('this'));
$printerStandard = new \ECSPrefix202402\PhpParser\PrettyPrinter\Standard();
echo $printerStandard->prettyPrint([$classMethod]);
File renamed without changes.
16 changes: 0 additions & 16 deletions build/rector-downgrade-php-72.php

This file was deleted.

10 changes: 0 additions & 10 deletions build/target-repository/.gitignore

This file was deleted.

22 changes: 0 additions & 22 deletions build/target-repository/composer.json

This file was deleted.

Loading

0 comments on commit 8aa33fe

Please sign in to comment.