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
18 changes: 9 additions & 9 deletions autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public static function load(string $className)
}

if (strpos(__DIR__, 'phar://') !== 0
&& @file_exists(__DIR__.'/../../autoload.php') === true
&& @file_exists(__DIR__ . '/../../autoload.php') === true
) {
self::$composerAutoloader = include __DIR__.'/../../autoload.php';
self::$composerAutoloader = include __DIR__ . '/../../autoload.php';
if (self::$composerAutoloader instanceof ClassLoader) {
self::$composerAutoloader->unregister();
self::$composerAutoloader->register();
Expand All @@ -99,16 +99,16 @@ public static function load(string $className)

if (substr($className, 0, 16) === 'PHP_CodeSniffer\\') {
if (substr($className, 0, 22) === 'PHP_CodeSniffer\Tests\\') {
$isInstalled = !is_dir(__DIR__.$ds.'tests');
$isInstalled = !is_dir(__DIR__ . $ds . 'tests');
if ($isInstalled === false) {
$path = __DIR__.$ds.'tests';
$path = __DIR__ . $ds . 'tests';
} else {
$path = '@test_dir@'.$ds.'PHP_CodeSniffer'.$ds.'CodeSniffer';
$path = '@test_dir@' . $ds . 'PHP_CodeSniffer' . $ds . 'CodeSniffer';
}

$path .= $ds.substr(str_replace('\\', $ds, $className), 22).'.php';
$path .= $ds . substr(str_replace('\\', $ds, $className), 22) . '.php';
} else {
$path = __DIR__.$ds.'src'.$ds.substr(str_replace('\\', $ds, $className), 16).'.php';
$path = __DIR__ . $ds . 'src' . $ds . substr(str_replace('\\', $ds, $className), 16) . '.php';
}
}

Expand All @@ -125,7 +125,7 @@ public static function load(string $className)
$className = substr($className, (strlen($nsPrefix) + 1));
}

$path = $searchPath.$ds.str_replace('\\', $ds, $className).'.php';
$path = $searchPath . $ds . str_replace('\\', $ds, $className) . '.php';
if (is_file($path) === true) {
break;
}
Expand Down Expand Up @@ -342,5 +342,5 @@ public static function getLoadedFiles()
// Register the autoloader before any existing autoloaders to ensure
// it gets a chance to hear about every autoload request, and record
// the file and class name for it.
spl_autoload_register(__NAMESPACE__.'\Autoload::load', true, true);
spl_autoload_register(__NAMESPACE__ . '\Autoload::load', true, true);
}//end if
4 changes: 2 additions & 2 deletions bin/phpcbf
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
*/

// Check if the PHP version and extensions comply with the minimum requirements before anything else.
require_once dirname(__DIR__).'/requirements.php';
require_once dirname(__DIR__) . '/requirements.php';
PHP_CodeSniffer\checkRequirements();

require_once dirname(__DIR__).'/autoload.php';
require_once dirname(__DIR__) . '/autoload.php';

$runner = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCBF();
Expand Down
4 changes: 2 additions & 2 deletions bin/phpcs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@
*/

// Check if the PHP version and extensions comply with the minimum requirements before anything else.
require_once dirname(__DIR__).'/requirements.php';
require_once dirname(__DIR__) . '/requirements.php';
PHP_CodeSniffer\checkRequirements();

require_once dirname(__DIR__).'/autoload.php';
require_once dirname(__DIR__) . '/autoload.php';

$runner = new PHP_CodeSniffer\Runner();
$exitCode = $runner->runPHPCS();
Expand Down
3 changes: 1 addition & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,13 @@
<rule ref="Squiz.Operators.ComparisonOperatorUsage"/>
<rule ref="Squiz.PHP.DisallowInlineIf"/>
<rule ref="Squiz.Scope.MethodScope"/>
<rule ref="Squiz.Strings.ConcatenationSpacing"/>
<rule ref="Squiz.Strings.DoubleQuoteUsage.NotRequired"/>
<rule ref="Generic.Strings.UnnecessaryHeredoc"/>
<rule ref="Squiz.WhiteSpace.ControlStructureSpacing"/>
<rule ref="Squiz.WhiteSpace.FunctionClosingBraceSpace"/>
<rule ref="Squiz.WhiteSpace.FunctionSpacing"/>
<rule ref="Squiz.WhiteSpace.MemberVarSpacing"/>
<rule ref="Squiz.WhiteSpace.OperatorSpacing"/>
<rule ref="PSR12.Operators.OperatorSpacing"/>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax">
<!-- Files involved in the requirements check should stay compatible with PHP 5.3. -->
Expand Down
8 changes: 4 additions & 4 deletions requirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function checkRequirements()

// Check the PHP version.
if (PHP_VERSION_ID < 70200) {
$error = 'ERROR: PHP_CodeSniffer requires PHP version 7.2.0 or greater.'.PHP_EOL;
$error = 'ERROR: PHP_CodeSniffer requires PHP version 7.2.0 or greater.' . PHP_EOL;
fwrite(STDERR, $error);
exit($exitCode);
}
Expand All @@ -55,17 +55,17 @@ function checkRequirements()
if (empty($missingExtensions) === false) {
$last = array_pop($requiredExtensions);
$required = implode(', ', $requiredExtensions);
$required .= ' and '.$last;
$required .= ' and ' . $last;

if (count($missingExtensions) === 1) {
$missing = $missingExtensions[0];
} else {
$last = array_pop($missingExtensions);
$missing = implode(', ', $missingExtensions);
$missing .= ' and '.$last;
$missing .= ' and ' . $last;
}

$error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.'.PHP_EOL;
$error = 'ERROR: PHP_CodeSniffer requires the %s extensions to be enabled. Please enable %s.' . PHP_EOL;
fwrite(STDERR, sprintf($error, $required, $missing));
exit($exitCode);
}
Expand Down
60 changes: 30 additions & 30 deletions scripts/build-phar.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
error_reporting(E_ALL);

if (ini_get('phar.readonly') === '1') {
echo 'Unable to build, phar.readonly in php.ini is set to read only.'.PHP_EOL;
echo 'Unable to build, phar.readonly in php.ini is set to read only.' . PHP_EOL;
exit(1);
}

require_once dirname(__DIR__).'/autoload.php';
require_once dirname(__DIR__).'/src/Util/Tokens.php';
require_once dirname(__DIR__) . '/autoload.php';
require_once dirname(__DIR__) . '/src/Util/Tokens.php';

if (defined('PHP_CODESNIFFER_VERBOSITY') === false) {
define('PHP_CODESNIFFER_VERBOSITY', 0);
Expand All @@ -54,13 +54,13 @@ function stripWhitespaceAndComments(string $fullpath, Config $config)
$tokenizer = new PHP($contents, $config, "\n");
$tokens = $tokenizer->getTokens();
} catch (TokenizerException $e) {
throw new RuntimeException('Failed to tokenize file '.$fullpath);
throw new RuntimeException('Failed to tokenize file ' . $fullpath);
}

$stripped = '';
foreach ($tokens as $token) {
if ($token['code'] === T_ATTRIBUTE_END || $token['code'] === T_OPEN_TAG) {
$stripped .= $token['content']."\n";
$stripped .= $token['content'] . "\n";
continue;
}

Expand All @@ -87,13 +87,13 @@ function stripWhitespaceAndComments(string $fullpath, Config $config)
];

foreach ($scripts as $script) {
echo "Building $script phar".PHP_EOL;
echo "Building $script phar" . PHP_EOL;

$pharName = $script.'.phar';
$pharFile = getcwd().'/'.$pharName;
echo "\t=> $pharFile".PHP_EOL;
$pharName = $script . '.phar';
$pharFile = getcwd() . '/' . $pharName;
echo "\t=> $pharFile" . PHP_EOL;
if (file_exists($pharFile) === true) {
echo "\t** file exists, removing **".PHP_EOL;
echo "\t** file exists, removing **" . PHP_EOL;
unlink($pharFile);
}

Expand All @@ -105,7 +105,7 @@ function stripWhitespaceAndComments(string $fullpath, Config $config)

echo "\t=> adding files... ";

$srcDir = realpath(__DIR__.'/../src');
$srcDir = realpath(__DIR__ . '/../src');
$srcDirLen = strlen($srcDir);

$rdi = new RecursiveDirectoryIterator($srcDir, RecursiveDirectoryIterator::FOLLOW_SYMLINKS);
Expand All @@ -123,11 +123,11 @@ function stripWhitespaceAndComments(string $fullpath, Config $config)
}

$fullpath = $file->getPathname();
if (strpos($fullpath, DIRECTORY_SEPARATOR.'Tests'.DIRECTORY_SEPARATOR) !== false) {
if (strpos($fullpath, DIRECTORY_SEPARATOR . 'Tests' . DIRECTORY_SEPARATOR) !== false) {
continue;
}

$path = 'src'.substr($fullpath, $srcDirLen);
$path = 'src' . substr($fullpath, $srcDirLen);

if (substr($filename, -4) === '.xml') {
$phar->addFile($fullpath, $path);
Expand All @@ -140,39 +140,39 @@ function stripWhitespaceAndComments(string $fullpath, Config $config)
}//end foreach

// Add requirements check.
$phar->addFromString('requirements.php', stripWhitespaceAndComments(realpath(__DIR__.'/../requirements.php'), $config));
$phar->addFromString('requirements.php', stripWhitespaceAndComments(realpath(__DIR__ . '/../requirements.php'), $config));

// Add autoloader.
$phar->addFromString('autoload.php', stripWhitespaceAndComments(realpath(__DIR__.'/../autoload.php'), $config));
$phar->addFromString('autoload.php', stripWhitespaceAndComments(realpath(__DIR__ . '/../autoload.php'), $config));

// Add licence file.
$phar->addFile(realpath(__DIR__.'/../licence.txt'), 'licence.txt');
$phar->addFile(realpath(__DIR__ . '/../licence.txt'), 'licence.txt');

echo 'done'.PHP_EOL;
echo "\t Added ".$fileCount.' files'.PHP_EOL;
echo 'done' . PHP_EOL;
echo "\t Added " . $fileCount . ' files' . PHP_EOL;

/*
Add the stub.
*/

echo "\t=> adding stub... ";
$stub = '#!/usr/bin/env php'."\n";
$stub .= '<?php'."\n";
$stub .= 'Phar::mapPhar(\''.$pharName.'\');'."\n";
$stub .= 'require_once "phar://'.$pharName.'/requirements.php";'."\n";
$stub .= 'PHP_CodeSniffer\checkRequirements();'."\n";
$stub .= 'require_once "phar://'.$pharName.'/autoload.php";'."\n";
$stub .= '$runner = new PHP_CodeSniffer\Runner();'."\n";
$stub .= '$exitCode = $runner->run'.$script.'();'."\n";
$stub .= 'exit($exitCode);'."\n";
$stub = '#!/usr/bin/env php' . "\n";
$stub .= '<?php' . "\n";
$stub .= 'Phar::mapPhar(\'' . $pharName . '\');' . "\n";
$stub .= 'require_once "phar://' . $pharName . '/requirements.php";' . "\n";
$stub .= 'PHP_CodeSniffer\checkRequirements();' . "\n";
$stub .= 'require_once "phar://' . $pharName . '/autoload.php";' . "\n";
$stub .= '$runner = new PHP_CodeSniffer\Runner();' . "\n";
$stub .= '$exitCode = $runner->run' . $script . '();' . "\n";
$stub .= 'exit($exitCode);' . "\n";
$stub .= '__HALT_COMPILER();';
$phar->setStub($stub);

echo 'done'.PHP_EOL;
echo 'done' . PHP_EOL;
}//end foreach

Timing::printRunTime();

echo PHP_EOL;
echo 'Filesize generated phpcs.phar file: '.number_format(filesize(dirname(__DIR__).'/phpcs.phar'), 0, ',', '.').' bytes'.PHP_EOL;
echo 'Filesize generated phpcs.phar file: '.number_format(filesize(dirname(__DIR__).'/phpcbf.phar'), 0, ',', '.').' bytes'.PHP_EOL;
echo 'Filesize generated phpcs.phar file: ' . number_format(filesize(dirname(__DIR__) . '/phpcs.phar'), 0, ',', '.') . ' bytes' . PHP_EOL;
echo 'Filesize generated phpcs.phar file: ' . number_format(filesize(dirname(__DIR__) . '/phpcbf.phar'), 0, ',', '.') . ' bytes' . PHP_EOL;
2 changes: 1 addition & 1 deletion scripts/get-requirements-check-matrix.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@

error_reporting(E_ALL);

require_once __DIR__.'/BuildRequirementsCheckMatrix.php';
require_once __DIR__ . '/BuildRequirementsCheckMatrix.php';

echo json_encode(['include' => (new PHP_CodeSniffer\BuildRequirementsCheckMatrix())->getBuilds()]);
Loading
Loading