aboutsummaryrefslogtreecommitdiff
path: root/lib/Minz
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2024-08-01 20:31:40 +0200
committerGravatar GitHub <noreply@github.com> 2024-08-01 20:31:40 +0200
commitd2247221bbf23a8fe19f66ea4ad7d0a59ffaa5b4 (patch)
treef5174c1b1d174cd41dca20f350e1297894e1c6fa /lib/Minz
parentb2c8cb74562b2f7cb290abd61ff1b6f35475f23a (diff)
Minor update whitespace PHPCS rules (#6666)
* Minor update whitespace PHPCS rules To simplify our configuration, apply more rules, and be clearer about what is added or removed compared with PSR12. Does not change our current conventions, but just a bit more consistent. * Forgotten *.phtml * Sort exclusion patterns + add a few for Extensions repo * Relaxed some rules
Diffstat (limited to 'lib/Minz')
-rw-r--r--lib/Minz/ActionController.php2
-rw-r--r--lib/Minz/ActionException.php2
-rw-r--r--lib/Minz/Configuration.php2
-rw-r--r--lib/Minz/ControllerNotActionControllerException.php2
-rw-r--r--lib/Minz/ControllerNotExistException.php2
-rw-r--r--lib/Minz/CurrentPagePaginationException.php2
-rw-r--r--lib/Minz/Dispatcher.php20
-rw-r--r--lib/Minz/Error.php4
-rw-r--r--lib/Minz/Exception.php6
-rw-r--r--lib/Minz/Extension.php56
-rw-r--r--lib/Minz/FileNotExistException.php4
-rw-r--r--lib/Minz/FrontController.php2
-rw-r--r--lib/Minz/Log.php30
-rw-r--r--lib/Minz/PDOConnectionException.php2
-rw-r--r--lib/Minz/Paginator.php10
-rw-r--r--lib/Minz/PermissionDeniedException.php4
-rw-r--r--lib/Minz/Url.php4
-rw-r--r--lib/Minz/View.php6
18 files changed, 80 insertions, 80 deletions
diff --git a/lib/Minz/ActionController.php b/lib/Minz/ActionController.php
index 12f14b0f4..350b3a9bb 100644
--- a/lib/Minz/ActionController.php
+++ b/lib/Minz/ActionController.php
@@ -51,7 +51,7 @@ abstract class Minz_ActionController {
$this->view = $view ?? new Minz_View();
$view_path = Minz_Request::controllerName() . '/' . Minz_Request::actionName() . '.phtml';
$this->view->_path($view_path);
- $this->view->attributeParams ();
+ $this->view->attributeParams();
}
/**
diff --git a/lib/Minz/ActionException.php b/lib/Minz/ActionException.php
index dafc47a15..158a03f88 100644
--- a/lib/Minz/ActionException.php
+++ b/lib/Minz/ActionException.php
@@ -7,6 +7,6 @@ class Minz_ActionException extends Minz_Exception {
$action_name = rawurlencode($action_name);
$message = "Invalid action name “{$action_name}” for controller “{$controller_name}”.";
- parent::__construct ($message, $code);
+ parent::__construct($message, $code);
}
}
diff --git a/lib/Minz/Configuration.php b/lib/Minz/Configuration.php
index 56733e481..7205f3009 100644
--- a/lib/Minz/Configuration.php
+++ b/lib/Minz/Configuration.php
@@ -106,7 +106,7 @@ class Minz_Configuration {
* @param Minz_ConfigurationSetterInterface $configuration_setter an optional helper to set values in configuration
* @throws Minz_FileNotExistException
*/
- private final function __construct(string $namespace, string $config_filename, string $default_filename = null,
+ final private function __construct(string $namespace, string $config_filename, string $default_filename = null,
Minz_ConfigurationSetterInterface $configuration_setter = null) {
$this->namespace = $namespace;
$this->config_filename = $config_filename;
diff --git a/lib/Minz/ControllerNotActionControllerException.php b/lib/Minz/ControllerNotActionControllerException.php
index 249ace2e1..25ba26d9f 100644
--- a/lib/Minz/ControllerNotActionControllerException.php
+++ b/lib/Minz/ControllerNotActionControllerException.php
@@ -5,6 +5,6 @@ class Minz_ControllerNotActionControllerException extends Minz_Exception {
public function __construct(string $controller_name, int $code = self::ERROR) {
$message = 'Controller `' . $controller_name . '` isn’t instance of ActionController';
- parent::__construct ($message, $code);
+ parent::__construct($message, $code);
}
}
diff --git a/lib/Minz/ControllerNotExistException.php b/lib/Minz/ControllerNotExistException.php
index 3ce181f09..6a9fee306 100644
--- a/lib/Minz/ControllerNotExistException.php
+++ b/lib/Minz/ControllerNotExistException.php
@@ -4,6 +4,6 @@ declare(strict_types=1);
class Minz_ControllerNotExistException extends Minz_Exception {
public function __construct(int $code = self::ERROR) {
$message = 'Controller not found!';
- parent::__construct ($message, $code);
+ parent::__construct($message, $code);
}
}
diff --git a/lib/Minz/CurrentPagePaginationException.php b/lib/Minz/CurrentPagePaginationException.php
index 7d70c5af8..25be755e3 100644
--- a/lib/Minz/CurrentPagePaginationException.php
+++ b/lib/Minz/CurrentPagePaginationException.php
@@ -5,6 +5,6 @@ class Minz_CurrentPagePaginationException extends Minz_Exception {
public function __construct(int $page) {
$message = 'Page number `' . $page . '` doesn’t exist';
- parent::__construct ($message, self::ERROR);
+ parent::__construct($message, self::ERROR);
}
}
diff --git a/lib/Minz/Dispatcher.php b/lib/Minz/Dispatcher.php
index 85f342dad..95460291f 100644
--- a/lib/Minz/Dispatcher.php
+++ b/lib/Minz/Dispatcher.php
@@ -41,22 +41,22 @@ final class Minz_Dispatcher {
self::$needsReset = false;
try {
- $this->createController (Minz_Request::controllerName ());
- $this->controller->init ();
- $this->controller->firstAction ();
+ $this->createController(Minz_Request::controllerName());
+ $this->controller->init();
+ $this->controller->firstAction();
// @phpstan-ignore booleanNot.alwaysTrue
if (!self::$needsReset) {
- $this->launchAction (
- Minz_Request::actionName ()
+ $this->launchAction(
+ Minz_Request::actionName()
. 'Action'
);
}
- $this->controller->lastAction ();
+ $this->controller->lastAction();
// @phpstan-ignore booleanNot.alwaysTrue
if (!self::$needsReset) {
$this->controller->declareCspHeader();
- $this->controller->view ()->build ();
+ $this->controller->view()->build();
}
} catch (Minz_Exception $e) {
throw $e;
@@ -87,14 +87,14 @@ final class Minz_Dispatcher {
}
if (!class_exists($controller_name)) {
- throw new Minz_ControllerNotExistException (
+ throw new Minz_ControllerNotExistException(
Minz_Exception::ERROR
);
}
$controller = new $controller_name();
if (!($controller instanceof Minz_ActionController)) {
- throw new Minz_ControllerNotActionControllerException (
+ throw new Minz_ControllerNotActionControllerException(
$controller_name,
Minz_Exception::ERROR
);
@@ -111,7 +111,7 @@ final class Minz_Dispatcher {
private function launchAction(string $action_name): void {
$call = [$this->controller, $action_name];
if (!is_callable($call)) {
- throw new Minz_ActionException (
+ throw new Minz_ActionException(
get_class($this->controller),
$action_name,
Minz_Exception::ERROR
diff --git a/lib/Minz/Error.php b/lib/Minz/Error.php
index e5a2cc794..74a71de0a 100644
--- a/lib/Minz/Error.php
+++ b/lib/Minz/Error.php
@@ -10,7 +10,7 @@ declare(strict_types=1);
* The Minz_Error class logs and raises framework errors
*/
class Minz_Error {
- public function __construct() { }
+ public function __construct() {}
/**
* Permet de lancer une erreur
@@ -76,7 +76,7 @@ class Minz_Error {
return array_merge($error, $warning, $notice);
case 'production':
default:
- return $error;
+ return $error;
}
}
}
diff --git a/lib/Minz/Exception.php b/lib/Minz/Exception.php
index 283b28f4e..c8c85912d 100644
--- a/lib/Minz/Exception.php
+++ b/lib/Minz/Exception.php
@@ -2,9 +2,9 @@
declare(strict_types=1);
class Minz_Exception extends Exception {
- const ERROR = 0;
- const WARNING = 10;
- const NOTICE = 20;
+ public const ERROR = 0;
+ public const WARNING = 10;
+ public const NOTICE = 20;
public function __construct(string $message = '', int $code = self::ERROR, ?Throwable $previous = null) {
if ($code !== Minz_Exception::ERROR
diff --git a/lib/Minz/Extension.php b/lib/Minz/Extension.php
index 0069e21cb..95d28af8a 100644
--- a/lib/Minz/Extension.php
+++ b/lib/Minz/Extension.php
@@ -87,7 +87,7 @@ abstract class Minz_Extension {
/**
* Set the current extension to enable.
*/
- public final function enable(): void {
+ final public function enable(): void {
$this->is_enabled = true;
}
@@ -96,7 +96,7 @@ abstract class Minz_Extension {
*
* @return bool true if extension is enabled, false otherwise.
*/
- public final function isEnabled(): bool {
+ final public function isEnabled(): bool {
return $this->is_enabled;
}
@@ -105,7 +105,7 @@ abstract class Minz_Extension {
*
* @return string|false html content from ext_dir/configure.phtml, false if it does not exist.
*/
- public final function getConfigureView() {
+ final public function getConfigureView() {
$filename = $this->path . '/configure.phtml';
if (!file_exists($filename)) {
return false;
@@ -127,26 +127,26 @@ abstract class Minz_Extension {
/**
* Getters and setters.
*/
- public final function getName(): string {
+ final public function getName(): string {
return $this->name;
}
- public final function getEntrypoint(): string {
+ final public function getEntrypoint(): string {
return $this->entrypoint;
}
- public final function getPath(): string {
+ final public function getPath(): string {
return $this->path;
}
- public final function getAuthor(): string {
+ final public function getAuthor(): string {
return $this->author;
}
- public final function getDescription(): string {
+ final public function getDescription(): string {
return $this->description;
}
- public final function getVersion(): string {
+ final public function getVersion(): string {
return $this->version;
}
/** @return 'system'|'user' */
- public final function getType() {
+ final public function getType() {
return $this->type;
}
@@ -159,7 +159,7 @@ abstract class Minz_Extension {
}
/** Return the user-specific, extension-specific, folder where this extension can save user-specific data */
- protected final function getExtensionUserPath(): string {
+ final protected function getExtensionUserPath(): string {
$username = Minz_User::name() ?: '_';
return USERS_PATH . "/{$username}/extensions/{$this->getEntrypoint()}";
}
@@ -174,12 +174,12 @@ abstract class Minz_Extension {
}
/** Return whether a user-specific, extension-specific, file exists */
- protected final function hasFile(string $filename): bool {
+ final protected function hasFile(string $filename): bool {
return file_exists($this->getExtensionUserPath() . '/' . $filename);
}
/** Return the user-specific, extension-specific, file content, or null if it does not exist */
- protected final function getFile(string $filename): ?string {
+ final protected function getFile(string $filename): ?string {
$content = @file_get_contents($this->getExtensionUserPath() . '/' . $filename);
return is_string($content) ? $content : null;
}
@@ -192,7 +192,7 @@ abstract class Minz_Extension {
* @param bool $isStatic indicates if the file is a static file or a user file. Default is static.
* @return string url corresponding to the file.
*/
- public final function getFileUrl(string $filename, string $type, bool $isStatic = true): string {
+ final public function getFileUrl(string $filename, string $type, bool $isStatic = true): string {
if ($isStatic) {
$dir = basename($this->path);
$file_name_url = urlencode("{$dir}/static/{$filename}");
@@ -215,21 +215,21 @@ abstract class Minz_Extension {
*
* @param string $base_name the base name of the controller. Final name will be FreshExtension_<base_name>_Controller.
*/
- protected final function registerController(string $base_name): void {
+ final protected function registerController(string $base_name): void {
Minz_Dispatcher::registerController($base_name, $this->path);
}
/**
* Register the views in order to be accessible by the application.
*/
- protected final function registerViews(): void {
+ final protected function registerViews(): void {
Minz_View::addBasePathname($this->path);
}
/**
* Register i18n files from ext_dir/i18n/
*/
- protected final function registerTranslates(): void {
+ final protected function registerTranslates(): void {
$i18n_dir = $this->path . '/i18n';
Minz_Translate::registerPath($i18n_dir);
}
@@ -240,7 +240,7 @@ abstract class Minz_Extension {
* @param string $hook_name the hook name (must exist).
* @param callable $hook_function the function name to call (must be callable).
*/
- protected final function registerHook(string $hook_name, $hook_function): void {
+ final protected function registerHook(string $hook_name, $hook_function): void {
Minz_ExtensionManager::addHook($hook_name, $hook_function);
}
@@ -279,7 +279,7 @@ abstract class Minz_Extension {
/**
* @return array<string,mixed>
*/
- protected final function getSystemConfiguration(): array {
+ final protected function getSystemConfiguration(): array {
if ($this->isConfigurationEnabled('system') && $this->isExtensionConfigured('system')) {
return FreshRSS_Context::systemConf()->extensions[$this->getName()];
}
@@ -289,7 +289,7 @@ abstract class Minz_Extension {
/**
* @return array<string,mixed>
*/
- protected final function getUserConfiguration(): array {
+ final protected function getUserConfiguration(): array {
if ($this->isConfigurationEnabled('user') && $this->isExtensionConfigured('user')) {
return FreshRSS_Context::userConf()->extensions[$this->getName()];
}
@@ -300,7 +300,7 @@ abstract class Minz_Extension {
* @param mixed $default
* @return mixed
*/
- public final function getSystemConfigurationValue(string $key, $default = null) {
+ final public function getSystemConfigurationValue(string $key, $default = null) {
if (!is_array($this->system_configuration)) {
$this->system_configuration = $this->getSystemConfiguration();
}
@@ -315,7 +315,7 @@ abstract class Minz_Extension {
* @param mixed $default
* @return mixed
*/
- public final function getUserConfigurationValue(string $key, $default = null) {
+ final public function getUserConfigurationValue(string $key, $default = null) {
if (!is_array($this->user_configuration)) {
$this->user_configuration = $this->getUserConfiguration();
}
@@ -354,13 +354,13 @@ abstract class Minz_Extension {
}
/** @param array<string,mixed> $configuration */
- protected final function setSystemConfiguration(array $configuration): void {
+ final protected function setSystemConfiguration(array $configuration): void {
$this->setConfiguration('system', $configuration);
$this->system_configuration = $configuration;
}
/** @param array<string,mixed> $configuration */
- protected final function setUserConfiguration(array $configuration): void {
+ final protected function setUserConfiguration(array $configuration): void {
$this->setConfiguration('user', $configuration);
$this->user_configuration = $configuration;
}
@@ -391,17 +391,17 @@ abstract class Minz_Extension {
$conf->save();
}
- protected final function removeSystemConfiguration(): void {
+ final protected function removeSystemConfiguration(): void {
$this->removeConfiguration('system');
$this->system_configuration = null;
}
- protected final function removeUserConfiguration(): void {
+ final protected function removeUserConfiguration(): void {
$this->removeConfiguration('user');
$this->user_configuration = null;
}
- protected final function saveFile(string $filename, string $content): void {
+ final protected function saveFile(string $filename, string $content): void {
$path = $this->getExtensionUserPath();
if (!file_exists($path)) {
@@ -411,7 +411,7 @@ abstract class Minz_Extension {
file_put_contents("{$path}/{$filename}", $content);
}
- protected final function removeFile(string $filename): void {
+ final protected function removeFile(string $filename): void {
$path = $path = $this->getExtensionUserPath() . '/' . $filename;
if (file_exists($path)) {
unlink($path);
diff --git a/lib/Minz/FileNotExistException.php b/lib/Minz/FileNotExistException.php
index 24cb1997a..c616a6f89 100644
--- a/lib/Minz/FileNotExistException.php
+++ b/lib/Minz/FileNotExistException.php
@@ -3,8 +3,8 @@ declare(strict_types=1);
class Minz_FileNotExistException extends Minz_Exception {
public function __construct(string $file_name, int $code = self::ERROR) {
- $message = 'File not found: `' . $file_name.'`';
+ $message = 'File not found: `' . $file_name . '`';
- parent::__construct ($message, $code);
+ parent::__construct($message, $code);
}
}
diff --git a/lib/Minz/FrontController.php b/lib/Minz/FrontController.php
index 09e986904..e57fb69c6 100644
--- a/lib/Minz/FrontController.php
+++ b/lib/Minz/FrontController.php
@@ -33,7 +33,7 @@ class Minz_FrontController {
* Constructeur
* Initialise le dispatcher, met à jour la Request
*/
- public function __construct () {
+ public function __construct() {
try {
$this->setReporting();
diff --git a/lib/Minz/Log.php b/lib/Minz/Log.php
index 4b884ae3b..648c2c663 100644
--- a/lib/Minz/Log.php
+++ b/lib/Minz/Log.php
@@ -39,21 +39,21 @@ class Minz_Log {
}
switch ($level) {
- case LOG_ERR :
- $level_label = 'error';
- break;
- case LOG_WARNING :
- $level_label = 'warning';
- break;
- case LOG_NOTICE :
- $level_label = 'notice';
- break;
- case LOG_DEBUG :
- $level_label = 'debug';
- break;
- default :
- $level = LOG_INFO;
- $level_label = 'info';
+ case LOG_ERR:
+ $level_label = 'error';
+ break;
+ case LOG_WARNING:
+ $level_label = 'warning';
+ break;
+ case LOG_NOTICE:
+ $level_label = 'notice';
+ break;
+ case LOG_DEBUG:
+ $level_label = 'debug';
+ break;
+ default:
+ $level = LOG_INFO;
+ $level_label = 'info';
}
$log = '[' . date('r') . '] [' . $level_label . '] --- ' . $information . "\n";
diff --git a/lib/Minz/PDOConnectionException.php b/lib/Minz/PDOConnectionException.php
index 391db5cae..46cd01432 100644
--- a/lib/Minz/PDOConnectionException.php
+++ b/lib/Minz/PDOConnectionException.php
@@ -5,6 +5,6 @@ class Minz_PDOConnectionException extends Minz_Exception {
public function __construct(string $error, string $user, int $code = self::ERROR) {
$message = 'Access to database is denied for `' . $user . '`: ' . $error;
- parent::__construct ($message, $code);
+ parent::__construct($message, $code);
}
}
diff --git a/lib/Minz/Paginator.php b/lib/Minz/Paginator.php
index df145f4bf..3b3c0961e 100644
--- a/lib/Minz/Paginator.php
+++ b/lib/Minz/Paginator.php
@@ -90,7 +90,7 @@ class Minz_Paginator {
return $i;
}
$i++;
- } while ($i < $this->nbItems ());
+ } while ($i < $this->nbItems());
return false;
}
@@ -102,7 +102,7 @@ class Minz_Paginator {
*/
public function itemByPosition(int $pos): Minz_Model {
if ($pos < 0) {
- $pos = $this->nbItems () - 1;
+ $pos = $this->nbItems() - 1;
}
if ($pos >= count($this->items)) {
$pos = 0;
@@ -120,7 +120,7 @@ class Minz_Paginator {
*/
public function items(bool $all = false): array {
$array = array ();
- $nbItems = $this->nbItems ();
+ $nbItems = $this->nbItems();
if ($nbItems <= $this->nbItemsPerPage || $all) {
$array = $this->items;
@@ -165,8 +165,8 @@ class Minz_Paginator {
$this->_nbPage();
}
public function _nbItemsPerPage(int $nbItemsPerPage): void {
- if ($nbItemsPerPage > $this->nbItems ()) {
- $nbItemsPerPage = $this->nbItems ();
+ if ($nbItemsPerPage > $this->nbItems()) {
+ $nbItemsPerPage = $this->nbItems();
}
if ($nbItemsPerPage < 0) {
$nbItemsPerPage = 0;
diff --git a/lib/Minz/PermissionDeniedException.php b/lib/Minz/PermissionDeniedException.php
index 240a8c3d4..fc85d60c6 100644
--- a/lib/Minz/PermissionDeniedException.php
+++ b/lib/Minz/PermissionDeniedException.php
@@ -3,8 +3,8 @@ declare(strict_types=1);
class Minz_PermissionDeniedException extends Minz_Exception {
public function __construct(string $file_name, int $code = self::ERROR) {
- $message = 'Permission is denied for `' . $file_name.'`';
+ $message = 'Permission is denied for `' . $file_name . '`';
- parent::__construct ($message, $code);
+ parent::__construct($message, $code);
}
}
diff --git a/lib/Minz/Url.php b/lib/Minz/Url.php
index 73edcf76d..310067382 100644
--- a/lib/Minz/Url.php
+++ b/lib/Minz/Url.php
@@ -81,13 +81,13 @@ class Minz_Url {
}
if (isset($url['c']) && is_string($url['c'])
- && $url['c'] != Minz_Request::defaultControllerName()) {
+ && $url['c'] != Minz_Request::defaultControllerName()) {
$uri .= $separator . 'c=' . $url['c'];
$separator = $and;
}
if (isset($url['a']) && is_string($url['a'])
- && $url['a'] != Minz_Request::defaultActionName()) {
+ && $url['a'] != Minz_Request::defaultActionName()) {
$uri .= $separator . 'a=' . $url['a'];
$separator = $and;
}
diff --git a/lib/Minz/View.php b/lib/Minz/View.php
index 717e47b15..44b7378b6 100644
--- a/lib/Minz/View.php
+++ b/lib/Minz/View.php
@@ -43,7 +43,7 @@ class Minz_View {
*/
public function change_view(string $controller_name, string $action_name): void {
Minz_Log::warning('Minz_View::change_view is deprecated, it will be removed in a future version. Please use Minz_View::_path instead.');
- $this->_path($controller_name. '/' . $action_name . '.phtml');
+ $this->_path($controller_name . '/' . $action_name . '.phtml');
}
/**
@@ -71,9 +71,9 @@ class Minz_View {
*/
public function build(): void {
if ($this->layout_filename !== '') {
- $this->buildLayout ();
+ $this->buildLayout();
} else {
- $this->render ();
+ $this->render();
}
}