style: Coding standards

pull/27/head
Matthieu Marcillaud 7 months ago
parent be6ad0e4ba
commit f8ae7e51b2

@ -1,6 +1,7 @@
<?php
namespace Spip\Loader\Compiler;
use SebastianBergmann\Timer\Duration;
use SebastianBergmann\Timer\ResourceUsageFormatter;
use SebastianBergmann\Timer\Timer;
@ -14,7 +15,6 @@ class Build {
private string $pharFilename,
private Timer $timer = new Timer(),
) {
}
public function prepare(): void {
@ -22,10 +22,12 @@ class Build {
mkdir($this->buildDirectory);
}
foreach ([
'spip_loader.php',
'version',
] as $clean_file) {
foreach (
[
'spip_loader.php',
'version',
] as $clean_file
) {
if (file_exists($this->buildDirectory . '/' . $clean_file)) {
unlink($this->buildDirectory . '/' . $clean_file);
}
@ -82,7 +84,7 @@ class Build {
}
private function parseResourceUsage(Duration $duration): array {
$usage = (new ResourceUsageFormatter)->resourceUsage($duration);
$usage = (new ResourceUsageFormatter())->resourceUsage($duration);
[$time, $memory] = explode(', ', $usage, 2);
return [
explode(': ', $time)[1],
@ -92,6 +94,6 @@ class Build {
private function MakeReadable($bytes) {
$i = floor(log($bytes, 1024));
return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]).['B','kiB','MiB','GiB','TiB'][$i];
return round($bytes / pow(1024, $i), [0,0,2,2,3][$i]) . ['B','kiB','MiB','GiB','TiB'][$i];
}
}

@ -6,7 +6,8 @@ use DateTimeImmutable;
use DateTimeZone;
class Git {
public function __construct(private string $directory = __DIR__) {}
public function __construct(private string $directory = __DIR__) {
}
public function setDirectory(string $directory) {
$this->directory = $directory;

@ -11,14 +11,14 @@ use RecursiveIteratorIterator;
use Seld\PharUtils\Timestamps;
class PharArchive {
private const FILENAME = 'spip_loader.phar';
public function __construct(
private string $sourceDirectory,
private string $buildDirectory,
private string $filename = self::FILENAME
) {}
) {
}
public function getPhpFiles(): Iterator {
$iterator = new RecursiveDirectoryIterator(
@ -26,7 +26,7 @@ class PharArchive {
RecursiveDirectoryIterator::SKIP_DOTS | FilesystemIterator::UNIX_PATHS
);
$iterator = new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST);
$iterator = new CallbackFilterIterator($iterator, function($file) {
$iterator = new CallbackFilterIterator($iterator, function ($file) {
/** @var \SplFileInfo $file */
if (!$file->isFile()) {
return false;
@ -82,37 +82,36 @@ class PharArchive {
rename($this->buildDirectory . '/' . self::FILENAME, $this->buildDirectory . '/' . $filename);
}
/**
* Removes whitespace from a PHP source string while preserving line numbers.
*
* @param string $source A PHP string
* @return string The PHP string with the whitespace removed
*/
private function stripWhitespace(string $source): string
{
if (!function_exists('token_get_all')) {
return $source;
}
/**
* Removes whitespace from a PHP source string while preserving line numbers.
*
* @param string $source A PHP string
* @return string The PHP string with the whitespace removed
*/
private function stripWhitespace(string $source): string {
if (!function_exists('token_get_all')) {
return $source;
}
$output = '';
foreach (token_get_all($source) as $token) {
if (is_string($token)) {
$output .= $token;
} elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
$output .= str_repeat("\n", substr_count($token[1], "\n"));
} elseif (T_WHITESPACE === $token[0]) {
// reduce wide spaces
$whitespace = Preg::replace('{[ \t]+}', ' ', $token[1]);
// normalize newlines to \n
$whitespace = Preg::replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
// trim leading spaces
$whitespace = Preg::replace('{\n +}', "\n", $whitespace);
$output .= $whitespace;
} else {
$output .= $token[1];
}
}
$output = '';
foreach (token_get_all($source) as $token) {
if (is_string($token)) {
$output .= $token;
} elseif (in_array($token[0], [T_COMMENT, T_DOC_COMMENT])) {
$output .= str_repeat("\n", substr_count($token[1], "\n"));
} elseif (T_WHITESPACE === $token[0]) {
// reduce wide spaces
$whitespace = Preg::replace('{[ \t]+}', ' ', $token[1]);
// normalize newlines to \n
$whitespace = Preg::replace('{(?:\r\n|\r|\n)}', "\n", $whitespace);
// trim leading spaces
$whitespace = Preg::replace('{\n +}', "\n", $whitespace);
$output .= $whitespace;
} else {
$output .= $token[1];
}
}
return $output;
}
return $output;
}
}

@ -13,7 +13,7 @@ $config = new Config(
new Internal(
__FILE__,
$request->server('SCRIPT_FILENAME'),
""
''
),
new Custom()
);
@ -32,13 +32,13 @@ $line
TEXT;
$rii = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(dirname(__DIR__)));
$files = array();
$files = [];
/** @var SplFileInfo $file */
foreach ($rii as $file) {
if ($file->isDir()){
continue;
}
if ($file->isDir()) {
continue;
}
echo $file->getPathname() . "\n";
echo $file->getPathname() . "\n";
}

@ -15,12 +15,12 @@ Phar::webPhar(
[
'svg' => 'image/svg+xml'
],
function($path) {
function ($path) {
$extension = pathinfo($path, \PATHINFO_EXTENSION);
if (in_array($extension, ['css', 'js', 'jpg', 'png', 'ico', 'svg'])) {
# Éviter Failed to load resource: net::ERR_HTTP2_PROTOCOL_ERROR (http/2)
# https://serverfault.com/questions/844526/apache-2-4-7-ignores-response-header-content-encoding-identity-instead-respect
header("Content-Encoding: none");
header('Content-Encoding: none');
# du cache dessus
header('Expires: ' . \date('r', time() + 86400 * 7));
}

@ -13,7 +13,6 @@ use Spip\Loader\Spip;
use Spip\Loader\Template\Page;
class ArchiveClean extends AbstractRoute implements RouteInterface {
const ETAPE = 'nettoyer';
public function match() {
# and file_exists($fichier)

@ -12,7 +12,6 @@ use Spip\Loader\Spip;
use Spip\Loader\Template\Page;
class ArchiveCopy extends AbstractRoute implements RouteInterface {
const ETAPE = 'copier';
public function match() {

@ -11,7 +11,6 @@ use Spip\Loader\Spip;
use Spip\Loader\Template\Page;
class ArchiveDecompress extends AbstractRoute implements RouteInterface {
const ETAPE = 'decompresser';
public function match() {

@ -13,7 +13,6 @@ use Spip\Loader\Spip;
use Spip\Loader\Template\Page;
class ArchiveDownload extends AbstractRoute implements RouteInterface {
const ETAPE = 'charger';
public function match() {

@ -1,7 +1,9 @@
<?xml version="1.0"?>
<ruleset>
<file>./loader/index.php</file>
<file>./loader/bin/console.php</file>
<file>./loader/phar/stub.php</file>
<file>./loader/src</file>
<file>./compiler</file>
<rule ref="SCS1" >
<exclude name="PSR12.Properties.ConstantVisibility" />

Loading…
Cancel
Save