chore: Corrections pour phpstan

pull/35/head
Matthieu Marcillaud 2 months ago
parent fad91ad59b
commit 395533fccc

@ -13,6 +13,7 @@ final class Stub {
const NAME = 'spip_loader.phar';
const AUTOLOADER = 'phar://spip_loader.phar/vendor/autoload.php';
/** @return void */
public function init() {
Phar::mapPhar(self::NAME);
if ($this->is_opcache_enabled()) {
@ -26,6 +27,7 @@ final class Stub {
Debug::add('COMPILATION_DATE', self::COMPILATION_DATE);
}
/** @return void */
public function handle() {
if ($this->is_route('warmup') && function_exists('opcache_reset')) {
// Route `spip_loader.php?warmup` that could help on some hosting and some opcache configs.
@ -41,12 +43,15 @@ final class Stub {
}
}
/** @return never */
public function handle_cli() {
require 'phar://spip_loader.phar/bin/console.php';
exit(0);
}
/** @return void */
public function handle_web() {
/** @phpstan-ignore-next-line */
if (self::DEBUG) {
Debug::enable();
}
@ -89,11 +94,16 @@ final class Stub {
});
}
/** @param \Throwable $e */
/**
* @param \Throwable $e
* @return void
*/
public static function show_on_debug($e) {
/** @phpstan-ignore-next-line */
if (!self::DEBUG) {
throw $e;
}
/** @phpstan-ignore-next-line */
echo $e->getMessage() . ' on file ' . $e->getFile() . ' on line ' . $e->getLine();
}
@ -121,6 +131,7 @@ try {
} catch (\Exception $e) {
// @note use \Throwable when PHP 7+
Stub::show_on_debug($e);
/** @phpstan-ignore-next-line */
} catch (\Error $e) {
Stub::show_on_debug($e);
}

@ -51,12 +51,15 @@ final class Internal extends AbstractConfig {
* Phar build adds '/index.php' in url that can be annoying.
* We save 'script_url' to send a <base href="xxx"> information to the browser.
*
* @param string $script_filename Local path of the primary script
* - inside phar : /[...]/opt/spip_loader/build/spip_loader.php
* - outside phar : /[...]/opt/spip_loader/loader/public/index.php
* @param string $script_url Url of the spip_loader.php script
* - inside phar : //loader.spip.test/build/spip_loader.php/index.php
* - outside phar : //loader.spip.test/loader/public/index.php
* @note
* SCRIPT_FILENAME : Local path of the primary script
* - inside phar : /[...]/opt/spip_loader/build/spip_loader.php
* - outside phar : /[...]/opt/spip_loader/loader/public/index.php
*
* $script_url Url of the spip_loader.php script
* - inside phar : //loader.spip.test/build/spip_loader.php
* - outside phar : //loader.spip.test/loader/public/index.php
* @param bool $is_cli
*/
public function __construct(RequestInterface $request, $is_cli = false) {
$script_filename = $request->server('SCRIPT_FILENAME');

@ -7,10 +7,16 @@ use Spip\Loader\Http\Request;
final class Debug {
/** @var bool */
private static $enable = false;
/** @var array<string, mixed> */
private static $bag = [];
/** @var Internal */
private $internal;
/** @var Request */
private $request;
public function __construct(Request $request, Internal $internal) {
@ -18,10 +24,16 @@ final class Debug {
$this->internal = $internal;
}
/**
* @param string $key
* @param mixed $value
* @return void;
*/
public static function add($key, $value) {
self::$bag[$key] = $value;
}
/** @return void */
public static function enable() {
if (!self::$enable) {
self::$enable = true;
@ -35,6 +47,7 @@ final class Debug {
}
}
/** @return string */
public function debug() {
return "<div class='msg-alert notice' style='margin-bottom:0'>"
. $this->table($this->internal->toArray())
@ -43,6 +56,7 @@ final class Debug {
. "</div>";
}
/** @return array<string, scalar> */
private function server_info() {
return [
'PATH_INFO' => $this->request->server('PATH_INFO'),
@ -55,6 +69,10 @@ final class Debug {
];
}
/**
* @param array<string, mixed> $data
* @return string
*/
private function table(array $data) {
$box = "<table style='margin: .75em 0;'>";
foreach ($data as $key => $val) {

@ -21,10 +21,19 @@ class Remote {
$this->client = new Client($options);
}
/**
* @param string $url
* @return \Psr\Http\Message\StreamInterface
*/
public function get($url) {
return $this->client->get($url)->getBody();
}
/**
* @param string $url
* @param string $destination_file
* @return void
*/
public function copyTo($url, $destination_file) {
$this->client->get($url, ['sink' => $destination_file]);
}

@ -56,6 +56,7 @@ class Debug extends AbstractRoute implements RouteInterface {
/**
* @param string $title
* @param array<string, mixed> $values
* @return string
*/
private function getTable($title, array $values) {

@ -21,7 +21,6 @@ class Spip {
private $script_filename;
/**
* @param string $url_root
* @param string $url_install
* @param string $full_install_directory
* @param string $install_directory

@ -140,6 +140,10 @@ class Template {
HTML;
}
/**
* @param string $file
* @return string
*/
protected function assets_path($file) {
return (\Phar::running(false) ? $this->app_filename . '?file=' : './') . sprintf('assets/%s', $file);
}

@ -8,9 +8,7 @@ parameters:
- loader/bin/console.php
- loader/phar/stub.php
- loader/public/index.php
- loader/lib/PclZip.php
- loader/src
excludePaths:
analyse:
- loader/lib/PclZip.php
scanDirectories:
- loader/vendor
level: 6

Loading…
Cancel
Save