summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Coevoet <stof@notk.org>2012-10-06 16:54:41 +0200
committerChristophe Coevoet <stof@notk.org>2012-10-06 16:54:41 +0200
commit754361d8b23b9c87731e786f81e57ccd5e1a481e (patch)
tree17eafe5f44cdce5da70a5011d18ef5d474737662
parent6c39ff14c7042bbe96bdf2e21e273b047982b0a4 (diff)
Fixed CS
-rw-r--r--lib/Bdu/Api.php48
-rw-r--r--lib/Bdu/Autoloader.php3
-rw-r--r--lib/Bdu/Configuration.php12
-rw-r--r--lib/Bdu/Container.php6
-rw-r--r--lib/Bdu/Entity/Association.php26
-rw-r--r--lib/Bdu/Entity/Mandate.php6
-rw-r--r--lib/Bdu/Entity/Position.php8
-rw-r--r--lib/Bdu/Entity/Student.php69
-rw-r--r--lib/Bdu/Exception/AssociationNotFound.php2
-rw-r--r--lib/Bdu/Exception/BadEncoding.php2
-rw-r--r--lib/Bdu/Exception/InvalidCredentials.php2
-rw-r--r--lib/Bdu/Exception/InvalidLogFile.php2
-rw-r--r--lib/Bdu/Exception/InvalidLogLevel.php2
-rw-r--r--lib/Bdu/Exception/LDAPConnectionFailed.php4
-rw-r--r--lib/Bdu/Exception/LDAPSearchFailed.php4
-rw-r--r--lib/Bdu/Exception/NotFound.php2
-rw-r--r--lib/Bdu/Exception/StudentNotFound.php2
-rw-r--r--lib/Bdu/Exception/WebserviceConnectionFailed.php2
-rw-r--r--lib/Bdu/Log/AbstractLogger.php8
-rw-r--r--lib/Bdu/Log/FileLogger.php5
-rw-r--r--lib/Bdu/Log/LoggerInterface.php16
-rw-r--r--lib/Bdu/Util/Encoder.php9
-rw-r--r--lib/Bdu/Util/Http/AdapterInterface.php4
-rw-r--r--lib/Bdu/Util/Http/Client.php16
-rw-r--r--lib/Bdu/Util/Http/CurlAdapter.php9
-rw-r--r--lib/Bdu/Util/Ldap.php15
-rw-r--r--lib/Bdu/Util/UnitOfWork.php45
-rw-r--r--lib/Bdu/Util/Unserializer.php43
-rw-r--r--test/Bdu/Tests/ConfigurationTest.php4
-rw-r--r--test/Bdu/Tests/TestCase.php25
-rw-r--r--test/Bdu/Tests/Util/LdapTest.php10
-rw-r--r--test/Bdu/Tests/Util/UnserializerTest.php8
32 files changed, 263 insertions, 156 deletions
diff --git a/lib/Bdu/Api.php b/lib/Bdu/Api.php
index 31b7040..e69b50a 100644
--- a/lib/Bdu/Api.php
+++ b/lib/Bdu/Api.php
@@ -44,9 +44,12 @@ class Bdu_Api
*
* Caractères génériques NON acceptés.
*
- * @param string $login Login EXACT de l'élève
+ * @param string $login Login EXACT de l'élève
* @param boolean $catch Si true (défaut) renvoie null en cas d'erreur, sinon lève l'exception
- * @return Bdu_Entity_Student un objet représentant l'élève ou null si l'élève n'existe pas
+ *
+ * @return Bdu_Entity_Student|null un objet représentant l'élève ou null si l'élève n'existe pas
+ *
+ * @throws Bdu_Exception
*/
public function searchStudentByLogin($login, $catch = true)
{
@@ -68,18 +71,19 @@ class Bdu_Api
* Caractères génériques autorisés.
* Limite de recherche: environ 25 élèves.
*
- * @param string $lastname Nom de famille
+ * @param string $lastname Nom de famille
* @param string $firstname Prénom
+ *
* @return array Tableau des élèves trouvés (objets de type Bdu_Entity_Student)
*/
public function searchStudentsByName($lastname, $firstname)
{
- if ($lastname <> "" && $firstname <> "") {
- $filter = sprintf("(&(cn=*%s*)(givenName=*%s*))", $lastname, $firstname);
- } elseif ($firstname <> "") {
- $filter = sprintf("givenName=*%s*", $firstname);
- } elseif ($lastname <> "") {
- $filter = sprintf("cn=*%s*", $lastname);
+ if ($lastname <> '' && $firstname <> '') {
+ $filter = sprintf('(&(cn=*%s*)(givenName=*%s*))', $lastname, $firstname);
+ } elseif ($firstname <> '') {
+ $filter = sprintf('givenName=*%s*', $firstname);
+ } elseif ($lastname <> '') {
+ $filter = sprintf('cn=*%s*', $lastname);
} else {
return array();
}
@@ -101,11 +105,12 @@ class Bdu_Api
* Pour le F il est nécessaire d'ajouter m ou d pour obtenir une réponse unique.
*
* @param string $roomname
+ *
* @return array Tableau des élèves occupant la chambre (0, 1 ou 2 élèves)
*/
public function searchStudentsByRoom($roomname)
{
- return $this->unitOfWork->search(sprintf("sdeRoomDN=cn=%s*", $roomname));
+ return $this->unitOfWork->search(sprintf('sdeRoomDN=cn=%s*', $roomname));
}
/**
@@ -114,11 +119,12 @@ class Bdu_Api
* Caractères génériques autorisés
*
* @param string $nickname Le surnom à chercher
+ *
* @return array Tableau des élèves trouvés
*/
public function searchStudentsByNick($nickname)
{
- return $this->unitOfWork->search(sprintf("sn=*%s*", $nickname));
+ return $this->unitOfWork->search(sprintf('sn=*%s*', $nickname));
}
/**
@@ -133,6 +139,7 @@ class Bdu_Api
* Il n'y aucune distinction entre nom, prénom, surnom, chambre, ...
*
* @param string $search Phrase de recherche
+ *
* @return array Tableau des élèves trouvés
*/
public function quickSearch($search)
@@ -145,7 +152,7 @@ class Bdu_Api
}
// split the different words and apply each of them
- $searchWords = array_unique(explode(" ", $search));
+ $searchWords = array_unique(explode(' ', $search));
$filters = array();
foreach ($searchWords as $word) {
@@ -169,11 +176,13 @@ class Bdu_Api
* @see http://en.wikipedia.org/wiki/Data_URI_scheme pour les explications sur le Data Scheme URI
*
* @param string $login Login de l'élève
+ *
* @return string Le Data URI Scheme pour la photo
*/
public function getStudentPhotoUrl($login)
{
$student = $this->searchStudentByLogin($login);
+
if (null === $student) {
return '';
}
@@ -189,6 +198,7 @@ class Bdu_Api
* défaut lorsque les membres d'une association sont récupérés.
*
* @param array $students Un tableau d'objets Bdu_Entity_Student
+ *
* @return array Le tableau donné en entrée
*/
public function batchRetrieveStudents(array $students)
@@ -202,6 +212,7 @@ class Bdu_Api
* Vérifie si un login est attribué
*
* @param string $login Login
+ *
* @return boolean
*/
public function isValidLogin($login)
@@ -212,11 +223,13 @@ class Bdu_Api
/**
* Recherche les associations par nom
*
- * @param string $name Nom de l'association
+ * @param string $name Nom de l'association
* @param boolean $exactMatch Si true, le nom exact est alors recherché
+ *
* @return array Tableau d'objets Bdu_Entity_Association
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
+ * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
*/
public function searchAssociationsByName($name, $exactMatch = false)
{
@@ -230,15 +243,18 @@ class Bdu_Api
* Recherche une association par id
*
* @param integer $id Nom de l'association
+ *
* @return Bdu_Entity_Association
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée ou n'est pas unique
+ * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée ou n'est pas unique
*/
public function searchAssociationById($id)
{
$association = $this->unitOfWork->getAssociation($id);
+
if (null !== $association) {
- // We still have the association so no need of a request
+ // We already have the association so no need of a request
return $association;
}
diff --git a/lib/Bdu/Autoloader.php b/lib/Bdu/Autoloader.php
index e45946a..c639fe0 100644
--- a/lib/Bdu/Autoloader.php
+++ b/lib/Bdu/Autoloader.php
@@ -27,9 +27,8 @@ class Bdu_Autoloader
/**
* Enregistre Bdu_Autoloader en tant qu'autoloader
*/
- static public function register()
+ public static function register()
{
- ini_set('unserialize_callback_func', 'spl_autoload_call');
spl_autoload_register(array(new self(), 'autoload'));
}
// @codeCoverageIgnoreEnd
diff --git a/lib/Bdu/Configuration.php b/lib/Bdu/Configuration.php
index 8d22e39..a500c48 100644
--- a/lib/Bdu/Configuration.php
+++ b/lib/Bdu/Configuration.php
@@ -115,16 +115,20 @@ class Bdu_Configuration
* accentués dans les résultats de recherches seront erronés
*
* @param string $charset "Latin9" ou "UTF-8" (défaut "UTF-8")
+ *
+ * @throws Bdu_Exception_BadEncoding si l'encodage est invalide
*/
- public function setCharset($charset = "UTF-8")
+ public function setCharset($charset = 'UTF-8')
{
switch ($charset) {
case 'UTF-8':
$this->charset = 'UTF-8';
+
return;
case 'Latin9':
$this->charset = 'ISO-8859-15';
+
return;
default:
@@ -150,9 +154,10 @@ class Bdu_Configuration
* Ces paramètres ont du vous être donné par un administrateur du SdE. Il est
* impératif d'appeler cette méthode avant toute autre appel à une méthode de la classe.
*
- * @param string $bindlogin Login de connexion
- * @param string $type Type d'utilisateur: TYPE_PEOPLE, TYPE_GROUP ou TYPE_APPLI
+ * @param string $bindlogin Login de connexion
+ * @param string $type Type d'utilisateur: TYPE_PEOPLE, TYPE_GROUP ou TYPE_APPLI
* @param string $credentials Credentials (mot de passe)
+ *
* @throws Bdu_Exception_InvalidCredentials si le type est invalide
*/
public function setCredentials($bindlogin, $type, $credentials)
@@ -172,6 +177,7 @@ class Bdu_Configuration
/**
* @return array
+ *
* @throws Bdu_Exception_UnsufficientConnectionParameters
*/
public function getCredentials()
diff --git a/lib/Bdu/Container.php b/lib/Bdu/Container.php
index 9d9e421..18a766f 100644
--- a/lib/Bdu/Container.php
+++ b/lib/Bdu/Container.php
@@ -58,7 +58,7 @@ class Bdu_Container
*
* @return Bdu_Container
*/
- static public function getInstance()
+ public static function getInstance()
{
if (null === self::$instance) {
return new self();
@@ -74,7 +74,7 @@ class Bdu_Container
*
* @return Bdu_Api
*/
- static public function getApiInstance()
+ public static function getApiInstance()
{
return self::getInstance()->getApi();
}
@@ -86,7 +86,7 @@ class Bdu_Container
*
* @return Bdu_Configuration
*/
- static public function getConfigurationInstance()
+ public static function getConfigurationInstance()
{
return self::getInstance()->getConfiguration();
}
diff --git a/lib/Bdu/Entity/Association.php b/lib/Bdu/Entity/Association.php
index cbd5921..d4b6718 100644
--- a/lib/Bdu/Entity/Association.php
+++ b/lib/Bdu/Entity/Association.php
@@ -90,11 +90,11 @@ class Bdu_Entity_Association
private $unitOfWork;
/**
- * @param integer $id
- * @param string $name
- * @param string $description
- * @param string $siteUrl
- * @param string $logoUrl
+ * @param integer $id
+ * @param string $name
+ * @param string $description
+ * @param string $siteUrl
+ * @param string $logoUrl
* @param Bdu_Util_UnitOfWork $unitOfWork
*/
public function __construct($id, $name, $description, $siteUrl, $logoUrl, Bdu_Util_UnitOfWork $unitOfWork)
@@ -167,7 +167,8 @@ class Bdu_Entity_Association
* étudiants sont utilisées, les récupérer en une fois est beaucoup plus
* efficace.
*
- * @param boolean $retrieve
+ * @param boolean $retrieve Whether the data of the students should be retrieved directly
+ *
* @return array Tableau d'objets Bdu_Entity_Student
*/
public function getCurrentStudents($retrieve = true)
@@ -200,7 +201,8 @@ class Bdu_Entity_Association
* étudiants sont utilisées, les récupérer en une fois est beaucoup plus
* efficace.
*
- * @param boolean $retrieve
+ * @param boolean $retrieve Whether the data of the students should be retrieved directly
+ *
* @return array Tableau d'objets Bdu_Entity_Student
*/
public function getAllStudents($retrieve = true)
@@ -227,8 +229,9 @@ class Bdu_Entity_Association
* Retourne la liste de tous les mandats en cours
*
* @return array Tableau d'objets Bdu_Entity_Mandate
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
+ * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
*/
public function getCurrentMandates()
{
@@ -243,8 +246,9 @@ class Bdu_Entity_Association
* Retourne la liste de tous les mandats, y compris ceux des anciens membres
*
* @return array Tableau d'objets Bdu_Entity_Mandate
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
+ * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
*/
public function getAllMandates()
{
@@ -259,8 +263,9 @@ class Bdu_Entity_Association
* Retourne les membres du bureau
*
* @return array Tableau d'objets Bdu_Entity_Mandate
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
+ * @throws Bdu_Exception_AssociationNotFound si l'association n'est pas trouvée
*/
public function getBoard()
{
@@ -275,6 +280,7 @@ class Bdu_Entity_Association
* Retourne l'url utilisée pour récupérer les données sur le webservice
*
* @param string $mode 'all' ou 'current'
+ *
* @return string
*/
private function getWebserviceUrl($mode)
diff --git a/lib/Bdu/Entity/Mandate.php b/lib/Bdu/Entity/Mandate.php
index 4cc2ec8..65bfce4 100644
--- a/lib/Bdu/Entity/Mandate.php
+++ b/lib/Bdu/Entity/Mandate.php
@@ -44,10 +44,10 @@ class Bdu_Entity_Mandate
private $end;
/**
- * @param Bdu_Entity_Student $student
+ * @param Bdu_Entity_Student $student
* @param Bdu_Entity_Position $position
- * @param DateTime $start
- * @param DateTime $end
+ * @param DateTime $start
+ * @param DateTime $end
*/
public function __construct(Bdu_Entity_Student $student, Bdu_Entity_Position $position, DateTime $start, DateTime $end = null)
{
diff --git a/lib/Bdu/Entity/Position.php b/lib/Bdu/Entity/Position.php
index 3356823..f920031 100644
--- a/lib/Bdu/Entity/Position.php
+++ b/lib/Bdu/Entity/Position.php
@@ -52,10 +52,10 @@ class Bdu_Entity_Position
/**
* Constructeur
*
- * @param integer $id
- * @param string $name
- * @param string $standardPosition
- * @param string $description
+ * @param integer $id
+ * @param string $name
+ * @param string $standardPosition
+ * @param string $description
* @param Bdu_Entity_Association $association
*/
public function __construct($id, $name, $standardPosition, $description, Bdu_Entity_Association $association)
diff --git a/lib/Bdu/Entity/Student.php b/lib/Bdu/Entity/Student.php
index 0263495..0afa957 100644
--- a/lib/Bdu/Entity/Student.php
+++ b/lib/Bdu/Entity/Student.php
@@ -88,7 +88,7 @@ class Bdu_Entity_Student
/**
* Constructeur
*
- * @param string $uid
+ * @param string $uid
* @param Bdu_Util_UnitOfWork $unitOfWork
*/
public function __construct($uid, Bdu_Util_UnitOfWork $unitOfWork)
@@ -101,14 +101,18 @@ class Bdu_Entity_Student
* Retourne le tableau des propriétés de l'élève
*
* @see getProperty() pour la liste des propriétés disponible
+ *
* @return array
+ *
* @throws Bdu_Exception_StudentNotFound si l'élève n'est pas trouvé
*/
public function getProperties()
{
$this->retrieve();
+
$prop = $this->prop;
- $prop["uid"] = $this->uid;
+ $prop['uid'] = $this->uid;
+
return $prop;
}
@@ -133,16 +137,19 @@ class Bdu_Entity_Student
* ce cas, la valeur retournée est null
*
* @param string $propname Propriété
+ *
* @return mixed Valeur
+ *
* @throws Bdu_Exception_StudentNotFound si l'élève n'est pas trouvé
*/
public function getProperty($propname)
{
- if ($propname == "uid") {
+ if ($propname == 'uid') {
return $this->uid;
}
$this->retrieve();
+
if (array_key_exists($propname, $this->prop)) {
return $this->prop[$propname];
}
@@ -168,8 +175,9 @@ class Bdu_Entity_Student
* @see http://en.wikipedia.org/wiki/Data_URI_scheme
*
* @return string Le Data URI Scheme pour la photo
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_StudentNotFound si l'étudiant n'est pas trouvé
+ * @throws Bdu_Exception_StudentNotFound si l'étudiant n'est pas trouvé
*/
public function getPhoto()
{
@@ -185,8 +193,9 @@ class Bdu_Entity_Student
* Retourne tous les mandats du membre
*
* @return array Tableau d'objets Bdu_Entity_Mandate
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_StudentNotFound si l'étudiant n'est pas trouvé
+ * @throws Bdu_Exception_StudentNotFound si l'étudiant n'est pas trouvé
*/
public function getAllMandates()
{
@@ -201,8 +210,9 @@ class Bdu_Entity_Student
* Retourne tous les mandats en cours du membre
*
* @return array Tableau d'objets Bdu_Entity_Mandate
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_StudentNotFound si l'étudiant n'est pas trouvé
+ * @throws Bdu_Exception_StudentNotFound si l'étudiant n'est pas trouvé
*/
public function getCurrentMandates()
{
@@ -222,12 +232,14 @@ class Bdu_Entity_Student
{
if (null === $this->currentAssociations) {
$associations = array ();
+
foreach ($this->getCurrentMandates() as $mandate) {
- /* @var $mandate Bdu_Entity_Mandate */
+ /** @var $mandate Bdu_Entity_Mandate */
if (!in_array($mandate->getPosition()->getAssociation(), $associations, true)) {
array_push($associations, $mandate->getPosition()->getAssociation());
}
}
+
$this->currentAssociations = $associations;
}
@@ -243,12 +255,14 @@ class Bdu_Entity_Student
{
if (null === $this->associations) {
$associations = array ();
+
foreach ($this->getAllMandates() as $mandate) {
- /* @var $mandate Bdu_Entity_Mandate */
+ /** @var $mandate Bdu_Entity_Mandate */
if (!in_array($mandate->getPosition()->getAssociation(), $associations, true)) {
array_push($associations, $mandate->getPosition()->getAssociation());
}
}
+
$this->associations = $associations;
}
@@ -262,8 +276,10 @@ class Bdu_Entity_Student
* Bdu_Api::batchRetrieveStudents dans votre code pour permettre d'avoir le
* second argument.
*
- * @param array $students
+ * @param array $students
* @param Bdu_Util_UnitOfWork $unitOfWork
+ *
+ * @throws InvalidArgumentException si le tableau passé en entrée contient autre chose que des objets Bdu_Entity_Student
*/
public static function batchRetrieve(array $students, Bdu_Util_UnitOfWork $unitOfWork)
{
@@ -272,6 +288,7 @@ class Bdu_Entity_Student
if (!$student instanceof Bdu_Entity_Student) {
throw new InvalidArgumentException('You must provide an array of Bdu_Entity_Student instances');
}
+
if (null === $student->prop) {
array_push($filters, sprintf('(uid=%s)', $student->getProperty('uid')));
}
@@ -287,6 +304,7 @@ class Bdu_Entity_Student
$filter = sprintf('(|%s)', implode('', $filters));
break;
}
+
$results = $unitOfWork->rawSearch($filter);
for ($i = 0; $i < $results['count']; $i++) {
@@ -306,13 +324,14 @@ class Bdu_Entity_Student
return;
}
- $student = $this->unitOfWork->rawSearch(sprintf("uid=%s", $this->uid), array_keys($this->getAttributes()));
+ $student = $this->unitOfWork->rawSearch(sprintf('uid=%s', $this->uid), array_keys($this->getAttributes()));
- if ($student["count"] == 0) {
- throw new Bdu_Exception_StudentNotFound("No such student");
+ if ($student['count'] == 0) {
+ throw new Bdu_Exception_StudentNotFound('No such student');
}
- if ($student["count"] > 1) {
- throw new Bdu_Exception_StudentNotFound("More than one student found");
+
+ if ($student['count'] > 1) {
+ throw new Bdu_Exception_StudentNotFound('More than one student found');
}
$this->setDatas($student[0]);
@@ -331,23 +350,22 @@ class Bdu_Entity_Student
// @codeCoverageIgnoreEnd
}
- $this->dn = $datas["dn"];
+ $this->dn = $datas['dn'];
$prop = array();
foreach ($this->getAttributes() as $key => $value) {
if ('mail' === $key) {
- if (isset($datas["mail"])) {
- $prop["mail"] = $datas["mail"];
- unset($prop["mail"]["count"]);
+ if (isset($datas['mail'])) {
+ $prop['mail'] = $datas['mail'];
+ unset($prop['mail']['count']);
} else {
- $prop["mail"] = array ();
+ $prop['mail'] = array ();
}
continue;
}
- $prop[$value] =
- (isset($datas[$key]) && !empty ($datas[$key][0]))
- ? $this->getValue($key, $datas[$key][0])
- : null;
+ $prop[$value] = (isset($datas[$key]) && !empty ($datas[$key][0]))
+ ? $this->getValue($key, $datas[$key][0])
+ : null;
}
$this->prop = $prop;
@@ -381,7 +399,9 @@ class Bdu_Entity_Student
$date->setDate($year, $month, $day);
return $date;
- } elseif ('supannlisterouge' === $key) {
+ }
+
+ if ('supannlisterouge' === $key) {
return 'true' === strtolower($value);
}
@@ -392,6 +412,7 @@ class Bdu_Entity_Student
* Retourne l'url utilisée pour récupérer les données sur le webservice
*
* @param string $mode 'all', 'current' ou 'photo'
+ *
* @return string
*/
private function getWebserviceUrl($mode)
diff --git a/lib/Bdu/Exception/AssociationNotFound.php b/lib/Bdu/Exception/AssociationNotFound.php
index 5cba615..23a3a64 100644
--- a/lib/Bdu/Exception/AssociationNotFound.php
+++ b/lib/Bdu/Exception/AssociationNotFound.php
@@ -24,7 +24,7 @@
*/
class Bdu_Exception_AssociationNotFound extends Bdu_Exception_NotFound
{
- public function __construct($message = "Could not found association")
+ public function __construct($message = 'Could not found association')
{
parent::__construct($message);
}
diff --git a/lib/Bdu/Exception/BadEncoding.php b/lib/Bdu/Exception/BadEncoding.php
index ea42a09..f4f350a 100644
--- a/lib/Bdu/Exception/BadEncoding.php
+++ b/lib/Bdu/Exception/BadEncoding.php
@@ -26,6 +26,6 @@ class Bdu_Exception_BadEncoding extends InvalidArgumentException implements Bdu_
{
public function __construct()
{
- parent::__construct("BDU connection failed: unsupported encoding");
+ parent::__construct('BDU connection failed: unsupported encoding');
}
}
diff --git a/lib/Bdu/Exception/InvalidCredentials.php b/lib/Bdu/Exception/InvalidCredentials.php
index d078e0b..ef14636 100644
--- a/lib/Bdu/Exception/InvalidCredentials.php
+++ b/lib/Bdu/Exception/InvalidCredentials.php
@@ -26,6 +26,6 @@ class Bdu_Exception_InvalidCredentials extends InvalidArgumentException implemen
{
public function __construct()
{
- parent::__construct("BDU connection failed: invalid credentials");
+ parent::__construct('BDU connection failed: invalid credentials');
}
}
diff --git a/lib/Bdu/Exception/InvalidLogFile.php b/lib/Bdu/Exception/InvalidLogFile.php
index 85c61f9..dc09fec 100644
--- a/lib/Bdu/Exception/InvalidLogFile.php
+++ b/lib/Bdu/Exception/InvalidLogFile.php
@@ -23,7 +23,7 @@
*/
class Bdu_Exception_InvalidLogFile extends RuntimeException implements Bdu_Exception
{
- public function __construct($message = "Logging failed")
+ public function __construct($message = 'Logging failed')
{
parent::__construct($message);
}
diff --git a/lib/Bdu/Exception/InvalidLogLevel.php b/lib/Bdu/Exception/InvalidLogLevel.php
index 839b35c..38deaba 100644
--- a/lib/Bdu/Exception/InvalidLogLevel.php
+++ b/lib/Bdu/Exception/InvalidLogLevel.php
@@ -23,7 +23,7 @@
*/
class Bdu_Exception_InvalidLogLevel extends InvalidArgumentException implements Bdu_Exception
{
- public function __construct($message = "Invalid logging level")
+ public function __construct($message = 'Invalid logging level')
{
parent::__construct($message);
}
diff --git a/lib/Bdu/Exception/LDAPConnectionFailed.php b/lib/Bdu/Exception/LDAPConnectionFailed.php
index 4907693..9a345bb 100644
--- a/lib/Bdu/Exception/LDAPConnectionFailed.php
+++ b/lib/Bdu/Exception/LDAPConnectionFailed.php
@@ -24,9 +24,9 @@
*/
class Bdu_Exception_LDAPConnectionFailed extends RuntimeException implements Bdu_Exception
{
- public function __construct($message = "Unknown error", $code = 0)
+ public function __construct($message = 'Unknown error', $code = 0)
{
- $message = "BDU LDAP connection failed: ".$message;
+ $message = 'BDU LDAP connection failed: '.$message;
parent::__construct($message, $code);
}
diff --git a/lib/Bdu/Exception/LDAPSearchFailed.php b/lib/Bdu/Exception/LDAPSearchFailed.php
index 7c7b892..51c4e33 100644
--- a/lib/Bdu/Exception/LDAPSearchFailed.php
+++ b/lib/Bdu/Exception/LDAPSearchFailed.php
@@ -24,9 +24,9 @@
*/
class Bdu_Exception_LDAPSearchFailed extends RuntimeException implements Bdu_Exception
{
- public function __construct($message = "Unknown error", $code = 0)
+ public function __construct($message = 'Unknown error', $code = 0)
{
- $message = "BDU LDAP search failed: ".$message;
+ $message = 'BDU LDAP search failed: '.$message;
parent::__construct($message, $code);
}
diff --git a/lib/Bdu/Exception/NotFound.php b/lib/Bdu/Exception/NotFound.php
index d86385a..fb51cbf 100644
--- a/lib/Bdu/Exception/NotFound.php
+++ b/lib/Bdu/Exception/NotFound.php
@@ -24,7 +24,7 @@
*/
class Bdu_Exception_NotFound extends InvalidArgumentException implements Bdu_Exception
{
- public function __construct($message = "Not found")
+ public function __construct($message = 'Not found')
{
parent::__construct($message);
}
diff --git a/lib/Bdu/Exception/StudentNotFound.php b/lib/Bdu/Exception/StudentNotFound.php
index 6242adb..45159ba 100644
--- a/lib/Bdu/Exception/StudentNotFound.php
+++ b/lib/Bdu/Exception/StudentNotFound.php
@@ -24,7 +24,7 @@
*/
class Bdu_Exception_StudentNotFound extends Bdu_Exception_NotFound
{
- public function __construct($message = "Could not find student")
+ public function __construct($message = 'Could not find student')
{
parent::__construct($message);
}
diff --git a/lib/Bdu/Exception/WebserviceConnectionFailed.php b/lib/Bdu/Exception/WebserviceConnectionFailed.php
index 0e8f99a..a898658 100644
--- a/lib/Bdu/Exception/WebserviceConnectionFailed.php
+++ b/lib/Bdu/Exception/WebserviceConnectionFailed.php
@@ -23,7 +23,7 @@
*/
class Bdu_Exception_WebserviceConnectionFailed extends RuntimeException implements Bdu_Exception
{
- public function __construct($message = "Webservice connection failed")
+ public function __construct($message = 'Webservice connection failed')
{
parent::__construct($message);
}
diff --git a/lib/Bdu/Log/AbstractLogger.php b/lib/Bdu/Log/AbstractLogger.php
index 4493c44..cd3bdcf 100644
--- a/lib/Bdu/Log/AbstractLogger.php
+++ b/lib/Bdu/Log/AbstractLogger.php
@@ -61,12 +61,15 @@ abstract class Bdu_Log_AbstractLogger implements Bdu_Log_LoggerInterface
* Constructeur de la classe
*
* @param integer $level Niveau de log (ERR par défaut)
+ *
+ * @throws Bdu_Exception_InvalidLogLevel
*/
public function __construct($level = self::ERR)
{
if (!array_key_exists($level, self::$levels)) {
throw new Bdu_Exception_InvalidLogLevel('Niveau de log invalide');
}
+
$this->level = $level;
}
@@ -114,6 +117,7 @@ abstract class Bdu_Log_AbstractLogger implements Bdu_Log_LoggerInterface
* Retourne le nom du niveau de log
*
* @param integer $level
+ *
* @return string
*/
protected static function getLevelName($level)
@@ -124,7 +128,7 @@ abstract class Bdu_Log_AbstractLogger implements Bdu_Log_LoggerInterface
/**
* Ecrit le message dans les logs
*
- * @param string $message
+ * @param string $message
* @param integer $priority
*/
abstract protected function write($message, $priority);
@@ -132,7 +136,7 @@ abstract class Bdu_Log_AbstractLogger implements Bdu_Log_LoggerInterface
/**
* Logue une message
*
- * @param string $message
+ * @param string $message
* @param integer $priority
*/
private function log($message, $priority)
diff --git a/lib/Bdu/Log/FileLogger.php b/lib/Bdu/Log/FileLogger.php
index 71fe01b..969b195 100644
--- a/lib/Bdu/Log/FileLogger.php
+++ b/lib/Bdu/Log/FileLogger.php
@@ -41,12 +41,15 @@ class Bdu_Log_FileLogger extends Bdu_Log_AbstractLogger
* Constructeur de la classe
*
* @param string $filename Nom complet du fichier de log
- * @param integer $level Niveau de log (ERR par défaut)
+ * @param int $level Niveau de log (ERR par défaut)
+ *
+ * @throws Bdu_Exception_InvalidLogFile
*/
public function __construct($filename, $level = self::ERR)
{
$this->filename = $filename;
$this->stream = @fopen($filename, 'a', false);
+
if (false === $this->stream) {
throw new Bdu_Exception_InvalidLogFile(sprintf('Impossible d\'ouvrir le fichier "%s"', $filename));
}
diff --git a/lib/Bdu/Log/LoggerInterface.php b/lib/Bdu/Log/LoggerInterface.php
index 9454f72..af87f88 100644
--- a/lib/Bdu/Log/LoggerInterface.php
+++ b/lib/Bdu/Log/LoggerInterface.php
@@ -30,7 +30,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function emerg($message);
+ public function emerg($message);
/**
* Logue un message avec la priorité ALERT
@@ -39,7 +39,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function alert($message);
+ public function alert($message);
/**
* Logue un message avec la priorité CRIT
@@ -48,7 +48,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function crit($message);
+ public function crit($message);
/**
* Logue un message avec la priorité ERR
@@ -57,7 +57,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function err($message);
+ public function err($message);
/**
* Logue un message avec la priorité WARN
@@ -66,7 +66,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function warn($message);
+ public function warn($message);
/**
* Logue un message avec la priorité NOTICE
@@ -75,7 +75,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function notice($message);
+ public function notice($message);
/**
* Logue un message avec la priorité INFO
@@ -84,7 +84,7 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function info($message);
+ public function info($message);
/**
* Logue un message avec la priorité DEBUG
@@ -93,5 +93,5 @@ interface Bdu_Log_LoggerInterface
*
* @param string $message
*/
- function debug($message);
+ public function debug($message);
}
diff --git a/lib/Bdu/Util/Encoder.php b/lib/Bdu/Util/Encoder.php
index 928943c..e2dadb8 100644
--- a/lib/Bdu/Util/Encoder.php
+++ b/lib/Bdu/Util/Encoder.php
@@ -33,11 +33,13 @@ class Bdu_Util_Encoder
/**
* @param Bdu_Configuration $configuration
+ *
* @throws RuntimeException si l'extension mbstring n'est pas disponible
*/
public function __construct(Bdu_Configuration $configuration)
{
$this->configuration = $configuration;
+
if (!extension_loaded('mbstring')) {
// @codeCoverageIgnoreStart
$logger = $this->configuration->getLogger();
@@ -54,6 +56,7 @@ class Bdu_Util_Encoder
* Convertit un tableau ou une chaîne en utf-8 depuis l'encodage de l'application
*
* @param array|string $data
+ *
* @return array|string
*/
public function convert($data)
@@ -65,6 +68,7 @@ class Bdu_Util_Encoder
* Convertit un tableau ou une chaîne utf-8 vers l'encodage de l'application
*
* @param array|string $data
+ *
* @return array|string
*/
public function unconvert($data)
@@ -76,7 +80,8 @@ class Bdu_Util_Encoder
* Convertit les valeurs d'un tableau de résultat dans l'encodage de sortie déclaré
*
* @param array|string $data Un tableau ou une chaine à convertir
- * @param boolean $way Sens de la conversion: true UTF-8->encod, false encod->UTF-8
+ * @param boolean $way Sens de la conversion: true UTF-8->encod, false encod->UTF-8
+ *
* @return array|string Chaine / Tableau converti
*/
private function convertEncoding($data, $way = true)
@@ -94,10 +99,12 @@ class Bdu_Util_Encoder
return $cdata;
}
+
if (is_string($data)) {
if ($way) {
return mb_convert_encoding($data, $charset, 'UTF-8');
}
+
return mb_convert_encoding($data, 'UTF-8', $charset);
}
diff --git a/lib/Bdu/Util/Http/AdapterInterface.php b/lib/Bdu/Util/Http/AdapterInterface.php
index 41448ba..c08f649 100644
--- a/lib/Bdu/Util/Http/AdapterInterface.php
+++ b/lib/Bdu/Util/Http/AdapterInterface.php
@@ -30,8 +30,10 @@ interface Bdu_Util_Http_AdapterInterface
* @param string $url
* @param string $bindDn
* @param string $credentials
+ *
* @return Bdu_Util_Http_Response
- * @throws Bdu_Exception_HttpError si la connexion curl échoue
+ *
+ * @throws Bdu_Exception_HttpError si la requête échoue
*/
public function request($url, $bindDn, $credentials);
}
diff --git a/lib/Bdu/Util/Http/Client.php b/lib/Bdu/Util/Http/Client.php
index dddbbeb..ec45f35 100644
--- a/lib/Bdu/Util/Http/Client.php
+++ b/lib/Bdu/Util/Http/Client.php
@@ -37,7 +37,7 @@ class Bdu_Util_Http_Client
private $adapter;
/**
- * @param Bdu_Configuration $configuration
+ * @param Bdu_Configuration $configuration
* @param Bdu_Util_Http_AdapterInterface $adapter
*/
public function __construct(Bdu_Configuration $configuration, Bdu_Util_Http_AdapterInterface $adapter)
@@ -47,19 +47,23 @@ class Bdu_Util_Http_Client
}
/**
- * @param $url
+ * @param string $url
+ *
* @return string
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_InvalidCredentials si le webservice renvoie une erreur 401 ou 403
- * @throws Bdu_Exception_NotFound si le webservice renvoie une erreur 404
+ * @throws Bdu_Exception_InvalidCredentials si le webservice renvoie une erreur 401 ou 403
+ * @throws Bdu_Exception_NotFound si le webservice renvoie une erreur 404
*/
public function request($url)
{
// perform the query
$logger = $this->configuration->getLogger();
+
if (null !== $logger) {
$logger->info(sprintf('Requête sur le webservice: %s', $url));
}
+
list($bindDn, $credentials) = $this->configuration->getCredentials();
try {
@@ -76,14 +80,17 @@ class Bdu_Util_Http_Client
case (401 === $statusCode):
case (403 === $statusCode):
$this->logError('Les identifiants sont erronés');
+
throw new Bdu_Exception_InvalidCredentials();
case (404 === $statusCode):
$this->logError(sprintf('Le webservice a renvoyé une erreur 404 pour l\'url "%s"', $url));
+
throw new Bdu_Exception_NotFound();
case (200 < $statusCode):
$this->logError(sprintf('Le webservice a renvoyé une erreur %d', $statusCode));
+
throw new Bdu_Exception_WebserviceConnectionFailed('Webservice unavailable');
}
@@ -93,6 +100,7 @@ class Bdu_Util_Http_Client
private function logError($message)
{
$logger = $this->configuration->getLogger();
+
if (null !== $logger) {
$logger->err($message);
}
diff --git a/lib/Bdu/Util/Http/CurlAdapter.php b/lib/Bdu/Util/Http/CurlAdapter.php
index 4456253..84ad5b0 100644
--- a/lib/Bdu/Util/Http/CurlAdapter.php
+++ b/lib/Bdu/Util/Http/CurlAdapter.php
@@ -31,20 +31,13 @@ class Bdu_Util_Http_CurlAdapter implements Bdu_Util_Http_AdapterInterface
*/
public function __construct()
{
- if (!extension_loaded('curl')){
+ if (!extension_loaded('curl')) {
// @codeCoverageIgnoreStart
throw new RuntimeException('The curl extension is needed');
// @codeCoverageIgnoreEnd
}
}
- /**
- * @param string $url
- * @param string $bindDn
- * @param string $credentials
- * @return Bdu_Util_Http_Response
- * @throws Bdu_Exception_HttpError si la connexion curl échoue
- */
public function request($url, $bindDn, $credentials)
{
// initialize the CURL session
diff --git a/lib/Bdu/Util/Ldap.php b/lib/Bdu/Util/Ldap.php
index d57c707..a6933eb 100644
--- a/lib/Bdu/Util/Ldap.php
+++ b/lib/Bdu/Util/Ldap.php
@@ -43,7 +43,8 @@ class Bdu_Util_Ldap
* Création de la connexion
*
* @param Bdu_Configuration $configuration
- * @param Bdu_Util_Encoder $encoder
+ * @param Bdu_Util_Encoder $encoder
+ *
* @throws RuntimeException si l'extension ldap n'est pas activée
*/
public function __construct(Bdu_Configuration $configuration, Bdu_Util_Encoder $encoder)
@@ -57,6 +58,7 @@ class Bdu_Util_Ldap
if (null !== $logger) {
$logger->err('L\'extension ldap est requise pour utiliser l\'API');
}
+
throw new RuntimeException('The ldap extension is needed');
// @codeCoverageIgnoreEnd
}
@@ -77,12 +79,15 @@ class Bdu_Util_Ldap
if (null !== $logger) {
$logger->debug('Connexion au ldap');
}
+
$this->connection = @ldap_connect($this->configuration->getLdapHost());
+
if (!$this->connection) {
// @codeCoverageIgnoreStart
if (null !== $logger) {
$logger->err('La connexion au ldap a échoué');
}
+
throw new Bdu_Exception_LDAPConnectionFailed();
// @codeCoverageIgnoreEnd
}
@@ -92,9 +97,11 @@ class Bdu_Util_Ldap
$bind = @ldap_bind($this->connection, $bindDn, utf8_encode($credentials));
if (!$bind) {
$error = @ldap_error($this->connection);
+
if (null !== $logger) {
$logger->err(sprintf('La connexion au ldap a échoué: %s', $error));
}
+
throw new Bdu_Exception_LDAPConnectionFailed($error);
}
}
@@ -110,7 +117,7 @@ class Bdu_Util_Ldap
* Recherche dans le LDAP
*
* @param string $filter Filtre de recherche
- * @param array $attrs (Facultatif) Liste des attributs à retourner
+ * @param array $attrs (Facultatif) Liste des attributs à retourner
*
* @return array Tableau de résultat LDAP
*
@@ -131,15 +138,17 @@ class Bdu_Util_Ldap
} else {
$search = @ldap_search($this->connection, $this->configuration->getLdapBaseDn(), $filter);
}
+
if (!$search) {
$error = @ldap_error($this->connection);
if (null !== $logger) {
$logger->err(sprintf('La recherche ldap a échoué: %s', $error));
}
+
throw new Bdu_Exception_LDAPSearchFailed($error);
}
- $results = ldap_get_entries($this->connection, $search);
+ $results = ldap_get_entries($this->connection, $search);
$results = $this->encoder->unconvert($results);
return $results;
diff --git a/lib/Bdu/Util/UnitOfWork.php b/lib/Bdu/Util/UnitOfWork.php
index 63738f7..cc634a4 100644
--- a/lib/Bdu/Util/UnitOfWork.php
+++ b/lib/Bdu/Util/UnitOfWork.php
@@ -77,8 +77,9 @@ class Bdu_Util_UnitOfWork
/**
* Renvoie l'entité Bdu_Entity_Student pour le login donné
*
- * @param string $uid
+ * @param string $uid
* @param boolean $retrieve Si true, récupère les données dans le ldap (utilisé pour vérifier la validité)
+ *
* @return Bdu_Entity_Student
*/
public function getStudent($uid, $retrieve = false)
@@ -103,6 +104,7 @@ class Bdu_Util_UnitOfWork
* Renvoie l'association avec l'id donné ou null si elle n'existe pas dans l'UnitOfWork
*
* @param integer $id
+ *
* @return Bdu_Entity_Association
*/
public function getAssociation($id)
@@ -118,10 +120,11 @@ class Bdu_Util_UnitOfWork
* Crée une association dans l'UnitOfWork
*
* @param integer $id
- * @param string $name
- * @param string $description
- * @param string $siteUrl
- * @param string $logoUrl
+ * @param string $name
+ * @param string $description
+ * @param string $siteUrl
+ * @param string $logoUrl
+ *
* @return Bdu_Entity_Association
*/
public function createAssociation($id, $name, $description, $siteUrl, $logoUrl)
@@ -137,6 +140,7 @@ class Bdu_Util_UnitOfWork
* Renvoie la fonction avec l'id donné ou null si elle n'existe pas dans l'UnitOfWork
*
* @param integer $id
+ *
* @return Bdu_Entity_Position
*/
public function getPosition($id)
@@ -151,11 +155,12 @@ class Bdu_Util_UnitOfWork
/**
* Crée une fonction dans l'UnitOfWork
*
- * @param integer $id
- * @param string $name
- * @param string $standardPosition
- * @param string $description
+ * @param integer $id
+ * @param string $name
+ * @param string $standardPosition
+ * @param string $description
* @param Bdu_Entity_Association $association
+ *
* @return Bdu_Entity_Position
*/
public function createPosition($id, $name, $standardPosition, $description, Bdu_Entity_Association $association)
@@ -171,11 +176,12 @@ class Bdu_Util_UnitOfWork
* Vérifie si un login est attribué
*
* @param string $login Login
+ *
* @return boolean
*/
public function isValidLogin($login)
{
- $result = $this->rawSearch(sprintf("uid=%s", $login), array("uid"));
+ $result = $this->rawSearch(sprintf('uid=%s', $login), array('uid'));
return (bool) $result['count'];
}
@@ -185,15 +191,16 @@ class Bdu_Util_UnitOfWork
* retourne les élèves correpondant au résultat
*
* @param string $filter Filtre de recherche LDAP
+ *
* @return array Tableau des élèves trouvés (objets de type Bdu_Entity_Student)
*/
public function search($filter)
{
- $result = $this->rawSearch($filter, array("uid"));
+ $result = $this->rawSearch($filter, array('uid'));
$students = array();
- for ($i = 0; $i < $result["count"]; $i++) {
- $uid = $result[$i]["uid"][0];
+ for ($i = 0; $i < $result['count']; $i++) {
+ $uid = $result[$i]['uid'][0];
if (!array_key_exists($uid, $students)) {
$students[$uid] = $this->getStudent($uid);
}
@@ -206,10 +213,11 @@ class Bdu_Util_UnitOfWork
* Effectue la recherche dans le LDAP pour un filtre donné et retourne le résultat
*
* @param string $filter Filtre de recherche LDAP
- * @param array $attrs Liste des attributs à retourner
+ * @param array $attrs Liste des attributs à retourner
+ *
* @return array Tableau des élèves trouvés (objets de type Bdu_Entity_Student)
*/
- public function rawSearch($filter, $attrs = array())
+ public function rawSearch($filter, array $attrs = array())
{
return $this->ldapConnection->search($filter, $attrs);
}
@@ -217,11 +225,13 @@ class Bdu_Util_UnitOfWork
/**
* Méthode pour récupérer les données du membre depuis le webservice
*
- * @param string $url Url pour récupérer les données du webservice
+ * @param string $url Url pour récupérer les données du webservice
* @param string $notFoundException Exception levée pour une erreur 404
+ *
* @return array
+ *
* @throws Bdu_Exception_WebserviceConnectionFailed si le webservice n'est pas accessible
- * @throws Bdu_Exception_NotFound si une erreur 404 est retournée
+ * @throws Bdu_Exception_NotFound si une erreur 404 est retournée
*/
public function request($url, $notFoundException = 'Bdu_Exception_NotFound')
{
@@ -235,7 +245,6 @@ class Bdu_Util_UnitOfWork
}
/**
- *
* @return Bdu_Util_Unserializer
*/
protected function getUnserializer()
diff --git a/lib/Bdu/Util/Unserializer.php b/lib/Bdu/Util/Unserializer.php
index bc66850..deb161d 100644
--- a/lib/Bdu/Util/Unserializer.php
+++ b/lib/Bdu/Util/Unserializer.php
@@ -44,9 +44,10 @@ class Bdu_Util_Unserializer
/**
* Constructeur
*
- * @param Bdu_Util_UnitOfWork $unitOfWork
- * @param Bdu_Util_Encoder $encoder
+ * @param Bdu_Util_UnitOfWork $unitOfWork
+ * @param Bdu_Util_Encoder $encoder
* @param Bdu_Log_LoggerInterface $logger
+ *
* @throws RuntimeException si l'extension json n'est pas disponible
*/
public function __construct(Bdu_Util_UnitOfWork $unitOfWork, Bdu_Util_Encoder $encoder, Bdu_Log_LoggerInterface $logger = null)
@@ -54,7 +55,8 @@ class Bdu_Util_Unserializer
$this->unitOfWork = $unitOfWork;
$this->encoder = $encoder;
$this->logger = $logger;
- if (!function_exists('json_decode')){
+
+ if (!function_exists('json_decode')) {
// @codeCoverageIgnoreStart
if (null !== $this->logger) {
$this->logger->err('L\'extension JSON est requise pour utiliser l\'API');
@@ -68,12 +70,15 @@ class Bdu_Util_Unserializer
* Traite une chaîne JSON
*
* @param string $string Chaîne JSON à traiter
+ *
* @return array Tableau des données traitées
+ *
* @throws InvalidArgumentException Si les données sont invalides
*/
public function unserialize($string)
{
$data = json_decode($string, true);
+
if (!is_array($data) || empty($data['type'])) {
if (null !== $this->logger) {
$this->logger->err(sprintf('Données invalides: %s', $string));
@@ -97,6 +102,7 @@ class Bdu_Util_Unserializer
* Traite les mandats
*
* @param array $data
+ *
* @return array
*/
private function parseMandates(array $data)
@@ -113,6 +119,7 @@ class Bdu_Util_Unserializer
* Traite les associations
*
* @param array $data
+ *
* @return array
*/
private function parseAssociations(array $data)
@@ -129,6 +136,7 @@ class Bdu_Util_Unserializer
* Traite un mandat
*
* @param array $mandate
+ *
* @return Bdu_Entity_Mandate
*/
private function parseMandate(array $mandate)
@@ -137,7 +145,7 @@ class Bdu_Util_Unserializer
$student = $this->unitOfWork->getStudent($mandate['student']['uid']);
$start = new DateTime('@'.$mandate['start']);
$endAttribute = $mandate['end'];
- $end = (null === $endAttribute) ? null : new DateTime('@'.$endAttribute);
+ $end = null === $endAttribute ? null : new DateTime('@'.$endAttribute);
return new Bdu_Entity_Mandate($student, $position, $start, $end);
}
@@ -146,6 +154,7 @@ class Bdu_Util_Unserializer
* Traite une fonction
*
* @param array $position
+ *
* @return Bdu_Entity_Position
*/
private function parsePosition(array $position)
@@ -153,32 +162,36 @@ class Bdu_Util_Unserializer
$id = $position['id'];
$entity = $this->unitOfWork->getPosition($id);
+
if (null !== $entity) {
- // We still have the position so we use it
+ // We already have the position so we use it
return $entity;
}
return $this->unitOfWork->createPosition(
- $id,
- $this->encoder->unconvert($position['name']),
- $this->encoder->unconvert($position['standardPosition']['name']),
- $this->encoder->unconvert($position['description']),
- $this->parseAssociation($position['association']));
+ $id,
+ $this->encoder->unconvert($position['name']),
+ $this->encoder->unconvert($position['standardPosition']['name']),
+ $this->encoder->unconvert($position['description']),
+ $this->parseAssociation($position['association'])
+ );
}
/**
* Traite une association
*
* @param array $association
+ *
* @return Bdu_Entity_Association
*/
private function parseAssociation(array $association)
{
return $this->unitOfWork->createAssociation(
- $association['id'],
- $this->encoder->unconvert($association['name']),
- $this->encoder->unconvert($association['description']),
- $this->encoder->unconvert($association['siteUrl']),
- $this->encoder->unconvert($association['logoUrl']));
+ $association['id'],
+ $this->encoder->unconvert($association['name']),
+ $this->encoder->unconvert($association['description']),
+ $this->encoder->unconvert($association['siteUrl']),
+ $this->encoder->unconvert($association['logoUrl'])
+ );
}
}
diff --git a/test/Bdu/Tests/ConfigurationTest.php b/test/Bdu/Tests/ConfigurationTest.php
index b876b7d..3fc7aac 100644
--- a/test/Bdu/Tests/ConfigurationTest.php
+++ b/test/Bdu/Tests/ConfigurationTest.php
@@ -82,10 +82,10 @@ class Bdu_Tests_ConfigurationTest extends PHPUnit_Framework_TestCase
$config->setLogger($logger);
$config->setCharset('Latin9');
- $this->assertEquals("ISO-8859-15", $config->getCharset());
+ $this->assertEquals('ISO-8859-15', $config->getCharset());
$config->setCharset('UTF-8');
- $this->assertEquals("UTF-8", $config->getCharset());
+ $this->assertEquals('UTF-8', $config->getCharset());
$this->setExpectedException('Bdu_Exception_BadEncoding');
try {
diff --git a/test/Bdu/Tests/TestCase.php b/test/Bdu/Tests/TestCase.php
index 618fe32..cf8daae 100644
--- a/test/Bdu/Tests/TestCase.php
+++ b/test/Bdu/Tests/TestCase.php
@@ -30,14 +30,25 @@ class Bdu_Tests_TestCase extends PHPUnit_Framework_TestCase
if (null === $login) {
$login = BDU_LDAP_LOGIN;
}
- if (BDU_LDAP_TYPE == "people") {
- return sprintf("uid=%s,ou=people,%s", $login, Bdu_Configuration::LDAP_ROOT);
- } elseif (BDU_LDAP_TYPE == "group") {
- return sprintf("uid=%s,ou=groups,%s", $login, Bdu_Configuration::LDAP_ROOT);
- } elseif (BDU_LDAP_TYPE == "appli") {
- return sprintf("uid=%s,ou=applications,%s", $login, Bdu_Configuration::LDAP_ROOT);
+
+ switch (BDU_LDAP_TYPE) {
+ case 'people':
+ $type = 'people';
+ break;
+
+ case 'group':
+ $type = 'groups';
+ break;
+
+ case 'appli':
+ $type = 'applications';
+ break;
+
+ default:
+ throw new Bdu_Exception_InvalidCredentials();
}
- throw new Bdu_Exception_InvalidCredentials();
+
+ return sprintf('uid=%s,ou=%s,%s', $login, $type, Bdu_Configuration::LDAP_ROOT);
}
public static function getLdapCredentials()
diff --git a/test/Bdu/Tests/Util/LdapTest.php b/test/Bdu/Tests/Util/LdapTest.php
index 848ef41..53b097e 100644
--- a/test/Bdu/Tests/Util/LdapTest.php
+++ b/test/Bdu/Tests/Util/LdapTest.php
@@ -25,9 +25,9 @@ class Bdu_Tests_Util_LdapTest extends Bdu_Tests_TestCase
$connection = new Bdu_Util_Ldap($config, new Bdu_Util_Encoder($config));
- $results = $connection->search("uid=11coevoetc", array("uid"));
+ $results = $connection->search('uid=11coevoetc', array('uid'));
$this->assertInternalType('array', $results, '->search returns an array');
- $this->assertEquals(array ("uid", 0, "count", "dn"), array_keys($results[0]));$messages = $logger->getMessages();
+ $this->assertEquals(array ('uid', 0, 'count', 'dn'), array_keys($results[0]));$messages = $logger->getMessages();
$this->assertTrue((bool) count($messages));
$message = end($messages);
$this->assertEquals('Recherche ldap avec le filtre "uid=11coevoetc" en filtrant les attributs ["uid"]', $message['message']);
@@ -41,11 +41,11 @@ class Bdu_Tests_Util_LdapTest extends Bdu_Tests_TestCase
$connection = new Bdu_Util_Ldap($config, new Bdu_Util_Encoder($config));
- $results = $connection->search(mb_convert_encoding("givenName=*Stéphane*", "ISO-8859-1", "UTF-8"));
+ $results = $connection->search(mb_convert_encoding('givenName=*Stéphane*', 'ISO-8859-1', 'UTF-8'));
$this->assertInternalType('array', $results, '->search returns an array');
- $firstName = $results[0]["givenname"][0];
- $this->assertEquals("ISO-8859-15", mb_detect_encoding($firstName, array ("UTF-8", "ISO-8859-15")), "->search converts the result back in the given encoding");
+ $firstName = $results[0]['givenname'][0];
+ $this->assertEquals('ISO-8859-15', mb_detect_encoding($firstName, array ('UTF-8', 'ISO-8859-15')), "->search converts the result back in the given encoding");
}
/**
diff --git a/test/Bdu/Tests/Util/UnserializerTest.php b/test/Bdu/Tests/Util/UnserializerTest.php
index 0e5efa3..1153870 100644
--- a/test/Bdu/Tests/Util/UnserializerTest.php
+++ b/test/Bdu/Tests/Util/UnserializerTest.php
@@ -121,10 +121,10 @@ class Bdu_Tests_Util_UnserializerTest extends Bdu_Tests_TestCase
private function getMandatesResponse()
{
- $startDate = new DateTime("yesterday");
- $start = $startDate->format("U");
- $endDate = new DateTime("now");
- $end = $endDate->format("U");
+ $startDate = new DateTime('yesterday');
+ $start = $startDate->format('U');
+ $endDate = new DateTime('now');
+ $end = $endDate->format('U');
return json_encode(array(
'type' => 'mandates',