diff --git a/autoloader.php b/autoloader.php index 2d314ed..d7e3d66 100755 --- a/autoloader.php +++ b/autoloader.php @@ -27,6 +27,8 @@ function autoloader($class) { if(is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$class . '.php')){ require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'src'.DIRECTORY_SEPARATOR.$class . '.php'; + }elseif(is_file(dirname(__FILE__).DIRECTORY_SEPARATOR.'managers'.DIRECTORY_SEPARATOR.$class . '.class.php')){ + require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'managers'.DIRECTORY_SEPARATOR.$class . '.class.php'; } } } diff --git a/coverage/StaticRepo.php.html b/coverage/StaticRepo.php.html index ff505c7..4b10219 100644 --- a/coverage/StaticRepo.php.html +++ b/coverage/StaticRepo.php.html @@ -51,22 +51,22 @@
0.00%
0 / 1
-
- 40.00% covered (danger) +
+ 50.00% covered (danger)
-
40.00%
-
2 / 5
+
50.00%
+
2 / 4
CRAP
-
- 58.06% covered (warning) +
+ 86.96% covered (warning)
-
58.06%
-
18 / 31
+
86.96%
+
40 / 46
@@ -80,47 +80,26 @@
0.00%
0 / 1
-
- 40.00% covered (danger) +
+ 50.00% covered (danger)
-
40.00%
-
2 / 5
- 62.01 +
50.00%
+
2 / 4
+ 38.88
-
- 58.06% covered (warning) +
+ 86.96% covered (warning)
-
58.06%
-
18 / 31
+
86.96%
+
40 / 46
-  __construct -
-
- 0.00% covered (danger) -
-
- -
0.00%
-
0 / 1
- 2 -
-
- 0.00% covered (danger) -
-
- -
0.00%
-
0 / 1
- - - -  getConnexion +  getConnexion
100.00% covered (success) @@ -141,7 +120,7 @@ -  testConnexion +  testConnexion
100.00% covered (success) @@ -162,7 +141,7 @@ -  delNumeric +  delNumeric
0.00% covered (danger) @@ -183,7 +162,7 @@ -  checkParam +  checkParam
0.00% covered (danger) @@ -192,15 +171,15 @@
0.00%
0 / 1
- 72 -
-
- 0.00% covered (danger) + 23.76 +
+
+ 84.62% covered (warning)
-
0.00%
-
0 / 10
+
84.62%
+
22 / 26
@@ -218,138 +197,155 @@     //contiens les informations de connexion a la BDD     private static $config; -     private function __construct(){ - -     } - -     /** -      * @return PDO instance de la connexion a la BDD -      */ -     public static function getConnexion(){ -         if(static::$config == null){ -             static::$config = json_decode(file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'config.json'),true); -         } -         if(static::$connexion == null){ -             static::$connexion = new PDO('mysql:host='.static::$config['host'].';dbname='.static::$config['database'], static::$config['login'], static::$config['password']); -         } -         return static::$connexion; -     } - -     /** -      * @return bool test de la Connexion -      */ -     public static function testConnexion(){ -         return static::getConnexion() instanceof PDO; -     } - - - - -     /* SUPPRIME LES VALEURS À CLÉS NUMÉRIQUES DANS UN FETCH D'UNE TABLE DE LA BDD +     /** +      * @return PDO instance de la connexion a la BDD +      */ +     public static function getConnexion(){ +         if(static::$config == null){ +             static::$config = json_decode(file_get_contents(dirname(__FILE__).DIRECTORY_SEPARATOR.'config.json'),true); +         } +         if(static::$connexion == null){ +             static::$connexion = new PDO('mysql:host='.static::$config['host'].';dbname='.static::$config['database'], static::$config['login'], static::$config['password']); +         } +         return static::$connexion; +     } + +     /** +      * @return bool test de la Connexion +      */ +     public static function testConnexion(){ +         return static::getConnexion() instanceof PDO; +     } + + + + +     /* SUPPRIME LES VALEURS À CLÉS NUMÉRIQUES DANS UN FETCH D'UNE TABLE DE LA BDD +     * +     * @fetchData<Array>                 le résultat d'une $requeteSQL->fetchAll() / $requeteSQL->fetch() +     * +     * @return newFetchData<Array>       retourne le tableau donné en paramètre mais sans les valeurs à clés numériques       * -     * @fetchData<Array>                 le résultat d'une $requeteSQL->fetchAll() / $requeteSQL->fetch() -     * -     * @return newFetchData<Array>       retourne le tableau donné en paramètre mais sans les valeurs à clés numériques   -     * -     */ -     public static function delNumeric($fetchData, $oneDimension=false){ -      -     // cas où fetch renvoie FALSE -     if( $fetchData === false ) return false; +     */ +     public static function delNumeric($fetchData, $oneDimension=false){ +      +     // cas où fetch renvoie FALSE +     if( $fetchData === false ) return false; + +         /* [1] 2 dimensions +         ===============================================*/ +         if( !$oneDimension ){ -         /* [1] 2 dimensions -         ===============================================*/ -         if( !$oneDimension ){ - -         // on supprime les doublons des entrées (indice numérique) -         for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs -             foreach($fetchData[$i] as $col => $val){  // pour toutes les entrées -                  -                 if( !mb_detect_encoding($val, 'UTF-8') ) -                     $fetchData[$i][$col] = utf8_encode($val); -                  -                 if( is_int($col) )                    // si l'indice est un entier -                     unset( $fetchData[$i][$col] );    // on le supprime -             } +         // on supprime les doublons des entrées (indice numérique) +         for( $i = 0 ; $i < count($fetchData) ; $i++ ) // pour tout les utilisateurs +             foreach($fetchData[$i] as $col => $val){  // pour toutes les entrées +                  +                 if( !mb_detect_encoding($val, 'UTF-8') ) +                     $fetchData[$i][$col] = utf8_encode($val); +                  +                 if( is_int($col) )                    // si l'indice est un entier +                     unset( $fetchData[$i][$col] );    // on le supprime +             } + +         /* [2] 1 dimensions +         ===============================================*/ +         }else{ -         /* [2] 1 dimensions -         ===============================================*/ -         }else{ - -             // on supprime les doublons des entrées (indice numérique) -             foreach($fetchData as $i=>$val){  // pour toutes les entrées -                  -                 if( !mb_detect_encoding($val, 'UTF-8') ) -                     $fetchData[$i] = utf8_encode($val); +             // on supprime les doublons des entrées (indice numérique) +             foreach($fetchData as $i=>$val){  // pour toutes les entrées +                  +                 if( !mb_detect_encoding($val, 'UTF-8') ) +                     $fetchData[$i] = utf8_encode($val); + +                 if( is_int($i) )                    // si l'indice est un entier +                     unset( $fetchData[$i] );    // on le supprime +             } -                 if( is_int($i) )                    // si l'indice est un entier -                     unset( $fetchData[$i] );    // on le supprime -             } - -         } +         } + +         return $fetchData; +     } + -         return $fetchData; -     } + + - - - - - //     _      _____ ___ _   _ ___ ____   - //    / \    |  ___|_ _| \ | |_ _|  _ \  - //   / _ \   | |_   | ||  \| || || |_) | - //  / ___ \  |  _|  | || |\  || ||  _ <  - // /_/   \_\ |_|   |___|_| \_|___|_| \_\ -                                       - -     /* Vérifie le type d'une variable + //     _      _____ ___ _   _ ___ ____   + //    / \    |  ___|_ _| \ | |_ _|  _ \  + //   / _ \   | |_   | ||  \| || || |_) | + //  / ___ \  |  _|  | || |\  || ||  _ <  + // /_/   \_\ |_|   |___|_| \_|___|_| \_\ +                                       + +     /* Vérifie le type d'une variable +     * +     * @variable<mixed>              la variable à vérifier           +     * @dbtype<String>               le type correspondant à la vérification +     *     * -     * @variable<mixed>              la variable à vérifier           -     * @dbtype<String>               le type correspondant à la vérification -     * -     * -     * @return correct<Boolean>      TRUE si le type est bon / FALSE si le type ne match pas -     * -     */ -     public static function checkParam($variable, $dbtype){ -         /* [1] on vérifie que $dbtype est un String -         =============================================================*/ -         if( !is_string($dbtype) ) return false; - - -         /* [2] Vérifications -         =============================================================*/ -         $checker = true; // contiendra VRAI si la vérification s'avère correcte - -         switch($dbtype){ -             // [1] 'M' / 'F'  -             case 'Civilité': -                 $checker = $checker && is_string($variable) && in_array(array('M', 'F'), $variable); -                 break; - -             // [2] Nom de patient  -             case 'Nom': -                 $checker = $checker && is_string($variable) && in_array(array('M', 'F'), $variable); -                 break; - - -             // [N] Type inconnu -             default: $checker = false; break; -         } - +     * @return correct<Boolean>      TRUE si le type est bon / FALSE si le type ne match pas +     * +     */ +     public static function checkParam($variable, $dbtype){ +         /* [1] on vérifie que $dbtype est un String +         =============================================================*/ +         if( !is_string($dbtype) ) return false; + + +         /* [2] Vérifications +         =============================================================*/ +         $checker = true; // contiendra VRAI si la vérification s'avère correcte +         $matches = []; +         //si on a un type scalairexlongueur, on traite +         if(preg_match_all('/((?:[a-z][a-z]+))(\\d+)/is',$dbtype,$matches)){ +             $dbtype = $matches[1][0]; +             isset($matches[2][0])? $len = $matches[2][0] : $len = 8; +         } + +         switch($dbtype){ +             // [1] 'M' / 'F'  +             case 'Civilite': +                 $checker = $checker && is_string($variable) && in_array($variable,['M','F']); +                 break; + +             // [2] Chaine de caractère (longueur variable) +             case 'String': +                 $checker = $checker && is_string($variable) && strlen($variable)<$len; +                 break; + +             case 'Integer': +                 $checker = $checker && is_int($variable) && $variable<pow(2,32); +                 break; -         /* [3] On retourne le résultat de la vérif -         =============================================================*/ -         return $checker; +             case 'SmallInteger': +                 $checker = $checker && is_int($variable) && $variable<pow(2,16); +                 break; -     } - - - } - - ?> +             case 'TinyInteger': +                 $checker = $checker && is_int($variable) && $variable<pow(2,8); +                 break; + +             case 'BigInteger': +                 $checker = $checker && is_int($variable) && $variable<pow(2,64); +                 break; + +             // [N] Type inconnu +             default: $checker = false; break; +         } + + +         /* [3] On retourne le résultat de la vérif +         =============================================================*/ +         return $checker; + +     } + + + } + + ?> @@ -362,7 +358,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/coverage/dashboard.html b/coverage/dashboard.html index 734991a..2ff72a3 100644 --- a/coverage/dashboard.html +++ b/coverage/dashboard.html @@ -58,7 +58,7 @@ - StaticRepo58% + StaticRepo86% @@ -75,7 +75,7 @@ - StaticRepo62 + StaticRepo38 @@ -113,10 +113,9 @@ - __construct0% - checkParam0% add83% - delNumeric85% + checkParam84% + delNumeric85% getAll85% add88% @@ -135,8 +134,8 @@ - checkParam72 - delNumeric10 + checkParam23 + delNumeric10 getAll4 add2 add2 @@ -149,7 +148,7 @@
@@ -170,7 +169,7 @@ $(document).ready(function() { .yAxis.tickFormat(d3.format('d')); d3.select('#classCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,1,0,0,0,4,0], "Class Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,1,4,0], "Class Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -188,7 +187,7 @@ $(document).ready(function() { .yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([2,0,0,0,0,0,0,0,0,4,2,17], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,5,2,18], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -238,7 +237,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[58.064516129032,23,"StaticRepo<\/a>"],[95.238095238095,7,"MedecinRepo<\/a>"],[96.428571428571,7,"PatientRepo<\/a>"],[92.682926829268,11,"RDVRepo<\/a>"],[91.304347826087,8,"StatsRepo<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[86.95652173913,36,"StaticRepo<\/a>"],[95.238095238095,7,"MedecinRepo<\/a>"],[96.428571428571,7,"PatientRepo<\/a>"],[92.682926829268,11,"RDVRepo<\/a>"],[92.307692307692,9,"StatsRepo<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -262,7 +261,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[0,1,"StaticRepo::__construct<\/a>"],[100,3,"StaticRepo::getConnexion<\/a>"],[100,1,"StaticRepo::testConnexion<\/a>"],[85.714285714286,10,"StaticRepo::delNumeric<\/a>"],[0,8,"StaticRepo::checkParam<\/a>"],[100,1,"MedecinRepo::getById<\/a>"],[83.333333333333,2,"MedecinRepo::add<\/a>"],[100,1,"MedecinRepo::delete<\/a>"],[100,1,"MedecinRepo::search<\/a>"],[100,1,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"PatientRepo::getById<\/a>"],[93.75,2,"PatientRepo::add<\/a>"],[100,1,"PatientRepo::delete<\/a>"],[100,1,"PatientRepo::updateMedecinTraitant<\/a>"],[100,1,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,1,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getByDate<\/a>"],[100,1,"RDVRepo::delete<\/a>"],[88.888888888889,2,"RDVRepo::add<\/a>"],[100,1,"RDVRepo::updateDateTime<\/a>"],[100,1,"RDVRepo::getByPatientAndDate<\/a>"],[85.714285714286,4,"RDVRepo::getAll<\/a>"],[91.304347826087,8,"StatsRepo::getAgePatient<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,3,"StaticRepo::getConnexion<\/a>"],[100,1,"StaticRepo::testConnexion<\/a>"],[85.714285714286,10,"StaticRepo::delNumeric<\/a>"],[84.615384615385,22,"StaticRepo::checkParam<\/a>"],[100,1,"MedecinRepo::getById<\/a>"],[83.333333333333,2,"MedecinRepo::add<\/a>"],[100,1,"MedecinRepo::delete<\/a>"],[100,1,"MedecinRepo::search<\/a>"],[100,1,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"PatientRepo::getById<\/a>"],[93.75,2,"PatientRepo::add<\/a>"],[100,1,"PatientRepo::delete<\/a>"],[100,1,"PatientRepo::updateMedecinTraitant<\/a>"],[100,1,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,1,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getByDate<\/a>"],[100,1,"RDVRepo::delete<\/a>"],[88.888888888889,2,"RDVRepo::add<\/a>"],[100,1,"RDVRepo::updateDateTime<\/a>"],[100,1,"RDVRepo::getByPatientAndDate<\/a>"],[85.714285714286,4,"RDVRepo::getAll<\/a>"],[91.304347826087,8,"StatsRepo::getAgePatient<\/a>"],[100,1,"StatsRepo::getRDVStat<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/coverage/index.html b/coverage/index.html index 09a644a..3ce42a8 100644 --- a/coverage/index.html +++ b/coverage/index.html @@ -41,23 +41,23 @@ - Total -
-
- 86.11% covered (warning) + Total +
+
+ 91.98% covered (success)
-
86.11%
-
124 / 144
+
91.98%
+
149 / 162
-
- 68.00% covered (warning) +
+ 72.00% covered (warning)
-
68.00%
-
17 / 25
+
72.00%
+
18 / 25
0.00% covered (danger) @@ -71,21 +71,21 @@ repos
-
- 93.81% covered (success) +
+ 93.97% covered (success)
-
93.81%
-
106 / 113
+
93.97%
+
109 / 116
-
- 75.00% covered (warning) +
+ 76.19% covered (warning)
-
75.00%
-
15 / 20
+
76.19%
+
16 / 21
0.00% covered (danger) @@ -99,21 +99,21 @@ StaticRepo.php
-
- 58.06% covered (warning) +
+ 86.96% covered (warning)
-
58.06%
-
18 / 31
+
86.96%
+
40 / 46
-
- 40.00% covered (danger) +
+ 50.00% covered (danger)
-
40.00%
-
2 / 5
+
50.00%
+
2 / 4
0.00% covered (danger) @@ -136,7 +136,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/coverage/repos/MedecinRepo.php.html b/coverage/repos/MedecinRepo.php.html index 292e2ec..da2a77c 100644 --- a/coverage/repos/MedecinRepo.php.html +++ b/coverage/repos/MedecinRepo.php.html @@ -301,7 +301,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/coverage/repos/PatientRepo.php.html b/coverage/repos/PatientRepo.php.html index b0e437c..453326f 100644 --- a/coverage/repos/PatientRepo.php.html +++ b/coverage/repos/PatientRepo.php.html @@ -318,7 +318,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/coverage/repos/RDVRepo.php.html b/coverage/repos/RDVRepo.php.html index 18797f6..9aaaa0c 100644 --- a/coverage/repos/RDVRepo.php.html +++ b/coverage/repos/RDVRepo.php.html @@ -295,18 +295,18 @@     }     public static function updateDateTime($idRDV,$dateTime){ -         $date = date('Y-m-d H:i:s',strtotime($dateTime)); -         $req = StaticRepo::getConnexion()->prepare('UPDATE RDV SET DateRDV = :date WHERE id = :id'); -         return $req->execute(['date' => $date, -             'id' => $idRDV]); +         $date = date('Y-m-d H:i:s',strtotime($dateTime)); +         $req = StaticRepo::getConnexion()->prepare('UPDATE RDV SET DateRDV = :date WHERE id = :id'); +         return $req->execute(['date' => $date, +             'id' => $idRDV]);     }     public static function getByPatientAndDate($idPatient,$date){ -         $date = date('Y-m-d',strtotime($date)); -         $req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE Patient_Id=:patient AND DATE(DateRDV)=:date'); -         $req->execute(['patient' => $idPatient, -             'date' => $date]); -         return StaticRepo::delNumeric($req->fetchAll()); +         $date = date('Y-m-d',strtotime($date)); +         $req = StaticRepo::getConnexion()->prepare('SELECT * FROM RDV WHERE Patient_Id=:patient AND DATE(DateRDV)=:date'); +         $req->execute(['patient' => $idPatient, +             'date' => $date]); +         return StaticRepo::delNumeric($req->fetchAll());     }     public static function getAll($date = 0){ @@ -341,7 +341,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/coverage/repos/StatsRepo.php.html b/coverage/repos/StatsRepo.php.html index 348fd47..6d55dc8 100644 --- a/coverage/repos/StatsRepo.php.html +++ b/coverage/repos/StatsRepo.php.html @@ -52,22 +52,22 @@
0.00%
0 / 1
-
- 0.00% covered (danger) +
+ 50.00% covered (danger)
-
0.00%
-
0 / 1
+
50.00%
+
1 / 2
CRAP
-
- 91.30% covered (success) +
+ 92.31% covered (success)
-
91.30%
-
21 / 23
+
92.31%
+
24 / 26
@@ -81,22 +81,22 @@
0.00%
0 / 1
-
- 0.00% covered (danger) +
+ 50.00% covered (danger)
-
0.00%
-
0 / 1
- 8.04 +
50.00%
+
1 / 2
+ 9.04
-
- 91.30% covered (success) +
+ 92.31% covered (success)
-
91.30%
-
21 / 23
+
92.31%
+
24 / 26
@@ -120,6 +120,27 @@
21 / 23
+ +  getRDVStat +
+
+ 100.00% covered (success) +
+
+ +
100.00%
+
1 / 1
+ 1 +
+
+ 100.00% covered (success) +
+
+ +
100.00%
+
3 / 3
+ + @@ -172,8 +193,14 @@         return ['H'=>$homme,'F'=>$femme];     } - - } +     public static function getRDVStat($medecin){ +         $req = StaticRepo::getConnexion()->prepare('SELECT count(*) NombreRDV FROM RDV WHERE Medecin_id = :medecin;'); +         $req->execute(['medecin'=>$medecin]); +         return StaticRepo::delNumeric($req->fetch(),true); +     } + + + } @@ -186,7 +213,7 @@ Dead Code

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/coverage/repos/dashboard.html b/coverage/repos/dashboard.html index f918d13..55251fd 100644 --- a/coverage/repos/dashboard.html +++ b/coverage/repos/dashboard.html @@ -143,7 +143,7 @@
@@ -182,7 +182,7 @@ $(document).ready(function() { .yAxis.tickFormat(d3.format('d')); d3.select('#methodCoverageDistribution svg') - .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,3,2,15], "Method Coverage")) + .datum(getCoverageDistributionData([0,0,0,0,0,0,0,0,0,3,2,16], "Method Coverage")) .transition().duration(500).call(chart); nv.utils.windowResize(chart.update); @@ -232,7 +232,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Cyclomatic Complexity'); d3.select('#classComplexity svg') - .datum(getComplexityData([[95.238095238095,7,"MedecinRepo<\/a>"],[96.428571428571,7,"PatientRepo<\/a>"],[92.682926829268,11,"RDVRepo<\/a>"],[91.304347826087,8,"StatsRepo<\/a>"]], 'Class Complexity')) + .datum(getComplexityData([[95.238095238095,7,"MedecinRepo<\/a>"],[96.428571428571,7,"PatientRepo<\/a>"],[92.682926829268,11,"RDVRepo<\/a>"],[92.307692307692,9,"StatsRepo<\/a>"]], 'Class Complexity')) .transition() .duration(500) .call(chart); @@ -256,7 +256,7 @@ $(document).ready(function() { chart.yAxis.axisLabel('Method Complexity'); d3.select('#methodComplexity svg') - .datum(getComplexityData([[100,1,"MedecinRepo::getById<\/a>"],[83.333333333333,2,"MedecinRepo::add<\/a>"],[100,1,"MedecinRepo::delete<\/a>"],[100,1,"MedecinRepo::search<\/a>"],[100,1,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"PatientRepo::getById<\/a>"],[93.75,2,"PatientRepo::add<\/a>"],[100,1,"PatientRepo::delete<\/a>"],[100,1,"PatientRepo::updateMedecinTraitant<\/a>"],[100,1,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,1,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getByDate<\/a>"],[100,1,"RDVRepo::delete<\/a>"],[88.888888888889,2,"RDVRepo::add<\/a>"],[100,1,"RDVRepo::updateDateTime<\/a>"],[100,1,"RDVRepo::getByPatientAndDate<\/a>"],[85.714285714286,4,"RDVRepo::getAll<\/a>"],[91.304347826087,8,"StatsRepo::getAgePatient<\/a>"]], 'Method Complexity')) + .datum(getComplexityData([[100,1,"MedecinRepo::getById<\/a>"],[83.333333333333,2,"MedecinRepo::add<\/a>"],[100,1,"MedecinRepo::delete<\/a>"],[100,1,"MedecinRepo::search<\/a>"],[100,1,"MedecinRepo::getPatients<\/a>"],[100,1,"MedecinRepo::getAll<\/a>"],[100,1,"PatientRepo::getById<\/a>"],[93.75,2,"PatientRepo::add<\/a>"],[100,1,"PatientRepo::delete<\/a>"],[100,1,"PatientRepo::updateMedecinTraitant<\/a>"],[100,1,"PatientRepo::search<\/a>"],[100,1,"PatientRepo::getAll<\/a>"],[100,1,"RDVRepo::getById<\/a>"],[100,1,"RDVRepo::getByDate<\/a>"],[100,1,"RDVRepo::delete<\/a>"],[88.888888888889,2,"RDVRepo::add<\/a>"],[100,1,"RDVRepo::updateDateTime<\/a>"],[100,1,"RDVRepo::getByPatientAndDate<\/a>"],[85.714285714286,4,"RDVRepo::getAll<\/a>"],[91.304347826087,8,"StatsRepo::getAgePatient<\/a>"],[100,1,"StatsRepo::getRDVStat<\/a>"]], 'Method Complexity')) .transition() .duration(500) .call(chart); diff --git a/coverage/repos/index.html b/coverage/repos/index.html index 8306ad9..b4a911f 100644 --- a/coverage/repos/index.html +++ b/coverage/repos/index.html @@ -44,21 +44,21 @@ Total
-
- 93.81% covered (success) +
+ 93.97% covered (success)
-
93.81%
-
106 / 113
+
93.97%
+
109 / 116
-
- 75.00% covered (warning) +
+ 76.19% covered (warning)
-
75.00%
-
15 / 20
+
76.19%
+
16 / 21
0.00% covered (danger) @@ -156,21 +156,21 @@ StatsRepo.php
-
- 91.30% covered (success) +
+ 92.31% covered (success)
-
91.30%
-
21 / 23
+
92.31%
+
24 / 26
-
- 0.00% covered (danger) +
+ 50.00% covered (danger)
-
0.00%
-
0 / 1
+
50.00%
+
1 / 2
0.00% covered (danger) @@ -193,7 +193,7 @@ High: 90% to 100%

- Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Wed Dec 9 12:35:41 UTC 2015. + Generated by PHP_CodeCoverage 3.0.2 using PHP 7.0.0 and PHPUnit 5.1.0 at Thu Dec 10 8:01:23 UTC 2015.

diff --git a/managers/Manager.class.php b/managers/Manager.class.php new file mode 100755 index 0000000..ba0a316 --- /dev/null +++ b/managers/Manager.class.php @@ -0,0 +1,64 @@ +listManagers = json_decode(file_get_contents($GLOBALS['managers_dir'].DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'managers.json'),true); + } + + /** + *recherche un manager ayant un nom et une commande identique aux paramètres et stocke le résultata dans l'objet + *pour une execution future + *@param String managerName Nom du manager a appeller + *@param String managerCommand Nom de la commande appellée + *@return bool manager trouvé + * + */ + public function match($managerName,$managerCommand){ + foreach($this->listManagers as $cleNom=>$manager){ + if($cleNom == $managerName){ + foreach($manager as $cleCommande=>$command){ + if($cleCommande == $managerCommand){ + // ajout du cas de l'authentificateur + $this->managerFound = new $managerName(); + $this->commandFound = $command; + return true; + } + } + } + } + return false; + } + + /** + * Execute la commande du manager trouvé, attention si la commande a besoin de paramètres, ils seront générés a partir + * de toutes les données passées en POST et les recherchera par clé, pensez donc a donner le bon nom aux inputs des formulaires + * pour que la commande trouve bien les variables + * + * @param array params Tableau de paramètre a passer a la commande + * @return json résultat rendu par le manager au format json + */ + + public function dispatch($params){ + if(($this->managerFound instanceof Authentification) or (Authentification::checkUser($this->commandFound['role'],$this->commandFound['strict']))){ + if(method_exists($this->managerFound,$this->commandFound['method'])){ + $evalCommand = '$this->managerFound->'.$this->commandFound['method'].'($params)?>'; + eval($evalCommand); + }else{ + Response::quickResponse(500,json_encode("La méthode: ".$this->commandFound['method'].' n\'est pas présente dans le manager')); + } + }else{ + Response::quickResponse(403,json_encode(['message' => 'vous n\'estes pas autorisé a faire cette action' ])); + } + } + +} +?> diff --git a/managers/Response.class.php b/managers/Response.class.php new file mode 100644 index 0000000..7b63073 --- /dev/null +++ b/managers/Response.class.php @@ -0,0 +1,202 @@ + '100 Continue', + 101 => '101 Switching Protocols', + //Successful 2xx + 200 => '200 OK', + 201 => '201 Created', + 202 => '202 Accepted', + 203 => '203 Non-Authoritative Information', + 204 => '204 No Content', + 205 => '205 Reset Content', + 206 => '206 Partial Content', + 226 => '226 IM Used', + //Redirection 3xx + 300 => '300 Multiple Choices', + 301 => '301 Moved Permanently', + 302 => '302 Found', + 303 => '303 See Other', + 304 => '304 Not Modified', + 305 => '305 Use Proxy', + 306 => '306 (Unused)', + 307 => '307 Temporary Redirect', + //Client Error 4xx + 400 => '400 Bad Request', + 401 => '401 Unauthorized', + 402 => '402 Payment Required', + 403 => '403 Forbidden', + 404 => '404 Not Found', + 405 => '405 Method Not Allowed', + 406 => '406 Not Acceptable', + 407 => '407 Proxy Authentication Required', + 408 => '408 Request Timeout', + 409 => '409 Conflict', + 410 => '410 Gone', + 411 => '411 Length Required', + 412 => '412 Precondition Failed', + 413 => '413 Request Entity Too Large', + 414 => '414 Request-URI Too Long', + 415 => '415 Unsupported Media Type', + 416 => '416 Requested Range Not Satisfiable', + 417 => '417 Expectation Failed', + 418 => '418 I\'m a teapot', + 422 => '422 Unprocessable Entity', + 423 => '423 Locked', + 426 => '426 Upgrade Required', + 428 => '428 Precondition Required', + 429 => '429 Too Many Requests', + 431 => '431 Request Header Fields Too Large', + //Server Error 5xx + 500 => '500 Internal Server Error', + 501 => '501 Not Implemented', + 502 => '502 Bad Gateway', + 503 => '503 Service Unavailable', + 504 => '504 Gateway Timeout', + 505 => '505 HTTP Version Not Supported', + 506 => '506 Variant Also Negotiates', + 510 => '510 Not Extended', + 511 => '511 Network Authentication Required' + ); + + /** + * Constructeur de la Response + * @param int $status status HTTP de la réponse (404,200,500, etc) + * @param bool|false $stream Si la réponse est un stream (avtive/désactive les méthodes send/stream() + * @param string $type type HTTP des données de retour + * @param bool|true $clearBuffer si activé, vide le buffer avant chaque envoi de donnée (a pour effet de ne pas afficher les echo/printf) + */ + public function __construct($status = 200,$stream = false,$type = 'application/json', $clearBuffer = false) + { + $this->status = $status; + array_push($this->headers,['Content-Type',$type]); + + $this->config['clearBuffer'] = $clearBuffer; + $this->config['stream'] = $stream; + } + + /** Ajoute du contenu a la réponse qui sera envoyé (par stream() ou par send() ) + * @param $content contenu a ajouter a la réponse + */ + public function write($content){ + $this->response .= $content; + } + + /** Envoie une partie de réponse au client (doit être récupéré en ajax, aucun intéret sinon), chaque bloc de donéne envoyé est séparé par + * un délimiteur ("//Block//" par défaut).ATTENTION: stream() vide la réponse (si on write() puis stream(), la réponse qu'il restera dans l'objet sera vide) + * @param string $content contenu a envoyer (optionnel car on peut utiliser la méthode write pour le faire) + * @throws Exception si la réponse n'est pas un stream + */ + public function stream($content="",$delimiter = "//Block//"){ + //vérification que la réponse est un stream + if(!$this->config['stream']){ + throw new Exception("Stream d'une réponse synchrone"); + } + //si les headers ne sont pas encore envoyés, on le fait + if(!headers_sent()){ + $this->sendHeader(); + } + //si demandé, on clear le buffer avant d'envoyer + if($this->config['clearBuffer']){ + ob_end_clean(); + if($GLOBALS['compression']){ + ob_start("ob_gzhandler"); + }else{ + ob_start(); + } + } + //on envoi le contenu de response et la variable content + if($this->response!=""){ + echo $delimiter.$this->response; + }if($content != ""){ + echo $delimiter.$content; + } + ob_flush();flush(); + $this->response = ''; + } + + /** + * Envoi les headers de la réponse (status et ceux potentiellement défnini par l'utilisateur) + */ + public function sendHeader(){ + //envoie le status de la requete (petit trick suivant l'architecture de PHP) + if (strpos(PHP_SAPI, 'cgi') === 0) { + header(sprintf('Status: %s', $this->Messages[$this->status])); + } else { + header(sprintf('HTTP/1.1 %s', $this->Messages[$this->status])); + } + //les autres headers + foreach($this->headers as $header){ + header(sprintf('%s: %s',$header[0],$header[1])); + } + } + + /** + * Défini un header qui sera envoyé + * @param $header Nom du header + * @param $value Valeur du header + */ + public function setHeader($header,$value){ + array_push($this->headers,[$header,$value]); + } + + /** Envoi la réponse et ferme la communication + * @throws Exception si la réponse est un stream + */ + public function send(){ + //vérification que la réponse n'est pas un stream + if($this->config['stream']){ + throw new Exception("Envoi synchrone d'une réponse stream"); + } + //si les headers ne sont pas encore envoyés, on le fait + if(!headers_sent()){ + $this->sendHeader(); + } + //si demandé, on clear le buffer avant d'envoyer + if($this->config['clearBuffer']){ + ob_end_clean(); + if($GLOBALS['compression']){ + ob_start("ob_gzhandler"); + }else{ + ob_start(); + } + } + //envoi de la réponse + echo $this->response; + //fermeture de la communication + header('Connection: close'); + header('Content-Length: '.ob_get_length()); + ob_end_flush(); + ob_flush(); + flush(); + //permet au reste du script de s'executer même si la réponse a été envoyé et que l'utilisateur interromp le script (changement de page, etc...) + ignore_user_abort(true); + } + + /** + * @param int $status status HTTP de la réponse (404,200,500, etc) + * @param $content + * @param string $type + */ + public static function quickResponse($status,$content,$type = 'application/json'){ + $response = new Response($status,false,$type); + $response->write($content); + $response->send(); + } +} \ No newline at end of file diff --git a/managers/config/managers.json b/managers/config/managers.json new file mode 100755 index 0000000..1784fc1 --- /dev/null +++ b/managers/config/managers.json @@ -0,0 +1,98 @@ +{ + "Authentification": { + "login":{"method": "authentification", + "role": 3, + "strict": false}, + "logout":{"method": "deconnection", + "role": 3, + "strict": false} + }, + "Eleves": { + "listByGroup": {"method": "getByGroupe", + "role": 2, + "strict": false}, + "listAll": {"method": "getAll", + "role": 2, + "strict": false}, + "importFromExcel": {"method":"importFromFile", + "role":1, + "strict":true + }, + "changeGroup": {"method":"changeGroup", + "role":1, + "strict":true + }, + "search": {"method":"search", + "role":2, + "strict":false + }, + "listByDiplome": {"method": "getByDiplome", + "role": 2, + "strict":false + }, + "getByCorrecteurAndControle":{"method": "getElevesByControleAndCorrecteur", + "role":1, + "strict":false} + }, + "Notes": { + "insert": {"method": "insert", + "role": 1, + "strict": true}, + "listAllEleve": {"method": "getAllNoteEleve", + "role": 3, + "strict" : true}, + "listAllByModuleEleve": {"method": "getAllNoteModuleEleve", + "role": 3, + "strict" : true}, + "updateComment": {"method": "updateComment", + "role": 1, + "strict" : true}, + "updateNote": {"method": "updateNote", + "role": 1, + "strict" : true}, + "exportAll": {"method": "exportAllNotes", + "role": 2, + "strict" : false} + }, + + "MCC": { + "importFromExcel": {"method": "importFromFile", + "role": 1, + "strict": true + }, + "getUEByCode": {"method": "getUEByCode", + "role": 3, + "strict": false + }, + "getUEByDiplome": {"method": "getUEByDiplome", + "role": 1, + "strict": true + }, + "getModuleByCode": {"method": "getModuleByCode", + "role": 1, + "strict": true + }, + "getControleByCode": {"method": "getControleByCode", + "role": 1, + "strict": true + }, + "getModuleByCodeUE": {"method": "getModuleByCodeUE", + "role": 1, + "strict": true + }, + "getControleByCodeModule": {"method": "getControleByCodeModule", + "role": 1, + "strict": true + } + }, + "Prof":{"getByControle":{"method":"getByControle", + "role" : 3, + "strict": false + }, + "setForCorrecteur":{"method":"setForControle", + "role":1, + "strict":true + } + + } +} diff --git a/managers/index.php b/managers/index.php new file mode 100755 index 0000000..233a8b8 --- /dev/null +++ b/managers/index.php @@ -0,0 +1,44 @@ +match($managerName,$managerCommand)){ + $manager->dispatch($_POST); + }else{ + $response = json_encode(['result' => false, + 'message' => "commande inexistante"]); + $objectResponse = new Response(404); + $objectResponse->write($response); + $objectResponse->send(); + } + +} +ob_end_clean(); +?> diff --git a/repositories/StaticRepo.php b/repositories/StaticRepo.php index 2855736..b1a84f6 100755 --- a/repositories/StaticRepo.php +++ b/repositories/StaticRepo.php @@ -8,10 +8,6 @@ class StaticRepo{ //contiens les informations de connexion a la BDD private static $config; - private function __construct(){ - - } - /** * @return PDO instance de la connexion a la BDD */ @@ -112,18 +108,39 @@ class StaticRepo{ /* [2] Vérifications =============================================================*/ $checker = true; // contiendra VRAI si la vérification s'avère correcte + $matches = []; + //si on a un type scalairexlongueur, on traite + if(preg_match_all('/((?:[a-z][a-z]+))(\\d+)/is',$dbtype,$matches)){ + $dbtype = $matches[1][0]; + isset($matches[2][0])? $len = $matches[2][0] : $len = 8; + } switch($dbtype){ // [1] 'M' / 'F' - case 'Civilité': - $checker = $checker && is_string($variable) && in_array(array('M', 'F'), $variable); + case 'Civilite': + $checker = $checker && is_string($variable) && in_array($variable,['M','F']); break; - // [2] Nom de patient - case 'Nom': - $checker = $checker && is_string($variable) && in_array(array('M', 'F'), $variable); + // [2] Chaine de caractère (longueur variable) + case 'String': + $checker = $checker && is_string($variable) && strlen($variable)<$len; break; + case 'Integer': + $checker = $checker && is_int($variable) && $variable$homme,'F'=>$femme]; } + public static function getRDVStat($medecin){ + $req = StaticRepo::getConnexion()->prepare('SELECT count(*) NombreRDV FROM RDV WHERE Medecin_id = :medecin;'); + $req->execute(['medecin'=>$medecin]); + return StaticRepo::delNumeric($req->fetch(),true); + } + } \ No newline at end of file diff --git a/test/RDVRepoTest.php b/test/RDVRepoTest.php index a4e5d03..1e10f8c 100644 --- a/test/RDVRepoTest.php +++ b/test/RDVRepoTest.php @@ -48,14 +48,14 @@ class RDVRepoTest extends PHPUnit_Framework_TestCase public function testGetByPAtientAndDate(){ $date = '2015-12-20 13:33:00'; - $this->assertTrue($this->repo->updateDateTime(85,$date)); + $this->assertTrue($this->repo->updateDateTime(1,$date)); $result = $this->repo->getByPatientAndDate(14,date('Y-m-d',strtotime($date))); $this->assertTrue(isset($result[0])); - $this->assertEquals($result[0]['Id'],85); + $this->assertEquals($result[0]['Id'],1); } public function testGetAll(){ - $this->assertEquals(count($this->repo->getAll(-1)),99); + $this->assertEquals(count($this->repo->getAll(-1)),98); $this->assertEquals(count($this->repo->getAll(0)),100); $this->assertEquals(count($this->repo->getAll(1)),2); } diff --git a/test/StaticRepoTest.php b/test/StaticRepoTest.php index 0827875..8a0b9a3 100644 --- a/test/StaticRepoTest.php +++ b/test/StaticRepoTest.php @@ -26,4 +26,30 @@ class StaticRepoTest extends PHPUnit_Framework_TestCase $this->assertEquals(StaticRepo::delNumeric($array),[0=>['kughk'=>'kjbk','azert'=>'aze'],1=>['kughk'=>'kjbk','azert'=>'aza']]); } + public function testCheckParam(){ + $this->assertTrue(StaticRepo::checkParam("Bonjour",'String20')); + $this->assertFalse(StaticRepo::checkParam("Bonjour",'String5')); + + $this->assertTrue(StaticRepo::checkParam("M",'Civilite')); + $this->assertTrue(StaticRepo::checkParam("F",'Civilite')); + $this->assertFalse(StaticRepo::checkParam("P",'Civilite')); + + $this->assertTrue(StaticRepo::checkParam(100,'Integer')); + $this->assertTrue(StaticRepo::checkParam(0,'Integer')); + $this->assertFalse(StaticRepo::checkParam(4294967296,'Integer')); + + $this->assertTrue(StaticRepo::checkParam(100,'TinyInteger')); + $this->assertTrue(StaticRepo::checkParam(0,'TinyInteger')); + $this->assertFalse(StaticRepo::checkParam(256,'TinyInteger')); + + $this->assertTrue(StaticRepo::checkParam(100,'SmallInteger')); + $this->assertTrue(StaticRepo::checkParam(0,'SmallInteger')); + $this->assertFalse(StaticRepo::checkParam(65536,'SmallInteger')); + + $this->assertTrue(StaticRepo::checkParam(100,'BigInteger')); + $this->assertTrue(StaticRepo::checkParam(0,'BigInteger')); + $this->assertFalse(StaticRepo::checkParam(18446744073700000000,'BigInteger')); + + $this->assertFalse(StaticRepo::checkParam('lololo','lolololo')); + } } diff --git a/test/StatsRepoTest.php b/test/StatsRepoTest.php index a747f76..4b1a135 100644 --- a/test/StatsRepoTest.php +++ b/test/StatsRepoTest.php @@ -14,4 +14,8 @@ class StatsRepoTest extends PHPUnit_Framework_TestCase $this->assertEquals(StatsRepo::getAgePatient(),$array); } + public function testRDVStat(){ + $this->assertEquals(StatsRepo::getRDVStat(2)['NombreRDV'],2); + } + }