From 68cd097dec623cd7226c74262cb543ddc7bba6ee Mon Sep 17 00:00:00 2001 From: Unknown Date: Tue, 27 Feb 2018 14:48:07 +0100 Subject: [PATCH] Fix framework with phpstan --- build/api/core/Config.php | 22 ++++++++++++++-------- build/api/core/Documentation.php | 6 +++++- build/api/core/Request.php | 6 +++--- build/api/module/admin.php | 9 +++++++++ build/api/module/release.php | 2 ++ build/database/core/DatabaseDriver.php | 4 ++-- build/error/core/Err.php | 11 +++++++++++ build/error/core/Error.php | 2 ++ build/router/controller/page.php | 1 + build/router/controller/redirect.php | 2 ++ build/router/core/Route.php | 2 -- build/router/core/Router.php | 2 -- 12 files changed, 51 insertions(+), 18 deletions(-) diff --git a/build/api/core/Config.php b/build/api/core/Config.php index 67a1553..d452ac3 100644 --- a/build/api/core/Config.php +++ b/build/api/core/Config.php @@ -37,22 +37,28 @@ ---------------------------------------------------------*/ { /* (1) Vérification existence fichier config */ - if( !file_exists($path) ) - return $this->error->set(Err::UnreachableResource); + if( !file_exists($path) ) { + $this->error->set(Err::UnreachableResource); + return; + } /* (2) Lecture fichier config */ $conf = @file_get_contents($path); /* (3) Si erreur lecture */ - if( $conf === false ) - return $this->error->set(Err::UnreachableResource); + if( $conf === false ) { + $this->error->set(Err::UnreachableResource); + return; + } /* (4) Parsage json */ $this->raw = json_decode( $conf, true ); /* (5) Gestion de l'erreur de parsage */ - if( $this->raw == null ) - return $this->error->set(Err::ParsingFailed, 'json'); + if( $this->raw == null ) { + $this->error->set(Err::ParsingFailed, 'json'); + return; + } } @@ -62,7 +68,7 @@ /* (1) Initialisation */ $this->index = []; - $ref = [ '/' => array_merge($this->raw) ]; + $ref = [ '/' => $this->raw ]; /* (2) Tant qu'il reste des @ref à traiter */ @@ -115,7 +121,7 @@ * @return inst Configuration singleton * ---------------------------------------------------------*/ - public static function get(){ + public static function get() : Config{ /* (1) If @inst already exists -> return singleton */ if( self::$inst instanceof Config ) diff --git a/build/api/core/Documentation.php b/build/api/core/Documentation.php index 693fcb1..bd160c2 100644 --- a/build/api/core/Documentation.php +++ b/build/api/core/Documentation.php @@ -20,7 +20,11 @@ /* (2) Builds the documentation * ---------------------------------------------------------*/ - public function generate(Request $rq=null){ + public static function generate(Request $rq=null){ + + if(is_null($rq)){ + return new Response(new Error(Err::NullRequest)); + } /* (1) Get data from config ---------------------------------------------------------*/ diff --git a/build/api/core/Request.php b/build/api/core/Request.php index ea2a4c0..aadc70a 100755 --- a/build/api/core/Request.php +++ b/build/api/core/Request.php @@ -38,7 +38,7 @@ ---------------------------------------------------------*/ public function __construct($uri=null, $params=null, $forced_method=null){ - return $this->buildRequestObject($uri, $params, $forced_method); + $this->buildRequestObject($uri, $params, $forced_method); } @@ -488,7 +488,7 @@ ---------------------------------------------------------*/ /* (1) S'il s'agit d'un téléchargement -> on dispatch */ if( $this->options['download'] === true ) - return $this->download(); + return $this->download($returned); /* (2) On construit la réponse avec l'erreur */ $response = new Response($this->error); @@ -506,7 +506,7 @@ /* (8) Gestion d'un téléchargement HTTP * */ - public function download(){ + public function download($returned){ /* (1) Vérification des erreurs et paramètres ---------------------------------------------------------*/ diff --git a/build/api/module/admin.php b/build/api/module/admin.php index 09265b0..2724f37 100644 --- a/build/api/module/admin.php +++ b/build/api/module/admin.php @@ -18,6 +18,7 @@ * ---------------------------------------------------------*/ public static function get($args){ + $id_admin = 0; extract($args); /* (1) If @id_admin is set -> get by id @@ -54,6 +55,9 @@ * ---------------------------------------------------------*/ public static function post($args){ + $username = ""; + $mail = ""; + $password = ""; extract($args); /* (1) Création admin */ @@ -80,6 +84,10 @@ * ---------------------------------------------------------*/ public static function put($args){ + //helps the static analysis + $mail = null; + $password = null; + $id_admin = 0; extract($args); /* (1) If @mail given @@ -123,6 +131,7 @@ * ---------------------------------------------------------*/ public static function delete($args){ + $id_admin = 0; extract($args); /* (1) Dispatch du status */ diff --git a/build/api/module/release.php b/build/api/module/release.php index 204b040..baa5c4f 100644 --- a/build/api/module/release.php +++ b/build/api/module/release.php @@ -15,6 +15,8 @@ * */ public function get($args){ + $project = ""; + $step = null; extract($args); /* (1) Load projects' configuration diff --git a/build/database/core/DatabaseDriver.php b/build/database/core/DatabaseDriver.php index 83007eb..9639b7b 100755 --- a/build/database/core/DatabaseDriver.php +++ b/build/database/core/DatabaseDriver.php @@ -77,7 +77,7 @@ // On signale que tout s'est bien passe $this->error = new Error(Err::Success); - }catch(Exception $e){ + }catch(\Exception $e){ // On signale qu'il y a une erreur $this->error = new Error(Err::PDOConnection); } @@ -148,7 +148,7 @@ is_null($label) && ($label = 'default'); /* (2) If no label, or unknown label */ - if( is_null($label) || !isset(self::$instance[$label]) ){ + if( !isset(self::$instance[$label]) ){ /* (2.1) Try to add the configuration if exists */ if( isset($conf[$label]) ){ diff --git a/build/error/core/Err.php b/build/error/core/Err.php index 449733e..d3f0371 100755 --- a/build/error/core/Err.php +++ b/build/error/core/Err.php @@ -63,6 +63,17 @@ const WrongParam = 17; /* (12) Erreur dans le traitement */ const ModuleError = 18; + /* (13) Erreur de format d'URI */ + const InvalidURI = 30; + /* (14) Erreur de paramètre par défaut */ + const WrongDefaultParam = 31; + /* (15) Erreur lorsque un download n'a pas de body */ + const MissingBody = 32; + /* (16) Erreur lorsqu'un download n'a pas de headers */ + const MissingHeaders = 33; + /* (17) Erreur lorsque la requete est null lors de la génération de documentation */ + const NullRequest = 34; + /* [5] Database diff --git a/build/error/core/Error.php b/build/error/core/Error.php index 9d2d2d0..3aeb804 100755 --- a/build/error/core/Error.php +++ b/build/error/core/Error.php @@ -21,6 +21,8 @@ * */ public function __construct($const){ + //make the static analisis happy + $tmp = $const; call_user_func_array([$this, 'set'], func_get_args()); } diff --git a/build/router/controller/page.php b/build/router/controller/page.php index 588b471..748e778 100644 --- a/build/router/controller/page.php +++ b/build/router/controller/page.php @@ -7,6 +7,7 @@ private $pagename; + private $uri; /* PRE-CALL * diff --git a/build/router/controller/redirect.php b/build/router/controller/redirect.php index 42cf86e..3ff879c 100644 --- a/build/router/controller/redirect.php +++ b/build/router/controller/redirect.php @@ -5,6 +5,7 @@ class redirect{ + private $url; /* PRE-CALL * @@ -12,6 +13,7 @@ * */ public function __construct($url){ + $this->url = $url; } diff --git a/build/router/core/Route.php b/build/router/core/Route.php index 83bfd95..4d7d2b9 100644 --- a/build/router/core/Route.php +++ b/build/router/core/Route.php @@ -10,8 +10,6 @@ * https://xdrm.io/ * **************************/ - use router\core\ControllerFactory; - namespace router\core; class Route{ diff --git a/build/router/core/Router.php b/build/router/core/Router.php index 19d7f1f..10fb9d7 100644 --- a/build/router/core/Router.php +++ b/build/router/core/Router.php @@ -10,8 +10,6 @@ * https://xdrm.io/ * **************************/ - use \router\core\ControllerFactory; - namespace router\core; class Router{