@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | /** |
| 20 | 20 | * Display the form. |
| 21 | 21 | */ |
| 22 | - public function view(){ |
|
| 22 | + public function view() { |
|
| 23 | 23 | $id = $this->request->getParam('id'); |
| 24 | 24 | |
| 25 | - if($id === null){ |
|
| 25 | + if ($id === null) { |
|
| 26 | 26 | print '<p>Paramètre non fournis.</p>'; |
| 27 | 27 | return; |
| 28 | 28 | } |
| 29 | 29 | |
| 30 | 30 | $flight = new \Bbcvols($this->db); |
| 31 | - if($flight->fetch($id) <= 0){ |
|
| 31 | + if ($flight->fetch($id) <= 0) { |
|
| 32 | 32 | print '<p>Vol non trouvé</p>'; |
| 33 | 33 | return; |
| 34 | 34 | } |
@@ -37,24 +37,24 @@ discard block |
||
| 37 | 37 | $form = new DamageCreationForm('damage_creation', $this->db); |
| 38 | 38 | $form->bind($command); |
| 39 | 39 | |
| 40 | - if($this->request->isPost()){ |
|
| 40 | + if ($this->request->isPost()) { |
|
| 41 | 41 | $form->setData($this->request->getPostParameters()); |
| 42 | 42 | |
| 43 | - if(!$form->validate()){ |
|
| 43 | + if (!$form->validate()) { |
|
| 44 | 44 | return $this->render('flight_damage/form.php', [ |
| 45 | 45 | 'form' => $form, |
| 46 | 46 | ]); |
| 47 | 47 | } |
| 48 | 48 | |
| 49 | - try{ |
|
| 49 | + try { |
|
| 50 | 50 | $this->handle($form->getObject()); |
| 51 | - }catch(\Exception $e){ |
|
| 51 | + } catch (\Exception $e) { |
|
| 52 | 52 | print $e->getMessage(); |
| 53 | 53 | dol_syslog($e->getMessage(), LOG_ERR); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | - $this->redirect($_SERVER["PHP_SELF"].'?id='.$id); |
|
| 57 | + $this->redirect($_SERVER["PHP_SELF"] . '?id=' . $id); |
|
| 58 | 58 | exit; |
| 59 | 59 | } |
| 60 | 60 | |
@@ -76,14 +76,14 @@ discard block |
||
| 76 | 76 | /** |
| 77 | 77 | * @return CreateDamageCommandHandler |
| 78 | 78 | */ |
| 79 | - private function getHandler(){ |
|
| 79 | + private function getHandler() { |
|
| 80 | 80 | return new CreateDamageCommandHandler($this->db, $this->getDamageRepository()); |
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | /** |
| 84 | 84 | * @return FlightDamageRepository |
| 85 | 85 | */ |
| 86 | - private function getDamageRepository(){ |
|
| 86 | + private function getDamageRepository() { |
|
| 87 | 87 | return new FlightDamageRepository($this->db); |
| 88 | 88 | } |
| 89 | 89 | |
@@ -48,7 +48,7 @@ |
||
| 48 | 48 | |
| 49 | 49 | try{ |
| 50 | 50 | $this->handle($form->getObject()); |
| 51 | - }catch(\Exception $e){ |
|
| 51 | + } catch(\Exception $e){ |
|
| 52 | 52 | print $e->getMessage(); |
| 53 | 53 | dol_syslog($e->getMessage(), LOG_ERR); |
| 54 | 54 | } |
@@ -13,11 +13,11 @@ |
||
| 13 | 13 | /** |
| 14 | 14 | * @return GetDamagesForFlightQueryRepositoryInterface |
| 15 | 15 | */ |
| 16 | - private function getDamagesRepository(){ |
|
| 16 | + private function getDamagesRepository() { |
|
| 17 | 17 | return new GetDamagesForFlightQueryRepository($this->db); |
| 18 | 18 | } |
| 19 | 19 | |
| 20 | - public function view(){ |
|
| 20 | + public function view() { |
|
| 21 | 21 | $flightId = $this->request->getParam('id'); |
| 22 | 22 | |
| 23 | 23 | return $this->render('flight_damage/view.php', [ |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | public function __construct(\DoliDB $db, $tableName) |
| 24 | 24 | { |
| 25 | 25 | $this->db = $db; |
| 26 | - $this->tableName = strpos($tableName, MAIN_DB_PREFIX) === 0 ? $tableName : MAIN_DB_PREFIX.$tableName; |
|
| 26 | + $this->tableName = strpos($tableName, MAIN_DB_PREFIX) === 0 ? $tableName : MAIN_DB_PREFIX . $tableName; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -33,18 +33,18 @@ discard block |
||
| 33 | 33 | * |
| 34 | 34 | * @throws \Exception |
| 35 | 35 | */ |
| 36 | - protected function write(array $elements){ |
|
| 36 | + protected function write(array $elements) { |
|
| 37 | 37 | $columns = join(',', array_keys($elements)); |
| 38 | - $values = join(',', array_map(function($value){ |
|
| 39 | - if(is_null($value)){ |
|
| 38 | + $values = join(',', array_map(function($value) { |
|
| 39 | + if (is_null($value)) { |
|
| 40 | 40 | return null; |
| 41 | 41 | } |
| 42 | 42 | |
| 43 | - if(is_bool($value)){ |
|
| 44 | - return (int)$value; |
|
| 43 | + if (is_bool($value)) { |
|
| 44 | + return (int) $value; |
|
| 45 | 45 | } |
| 46 | 46 | |
| 47 | - return is_string($value) ? $this->db->escape($value) : $value ; |
|
| 47 | + return is_string($value) ? $this->db->escape($value) : $value; |
|
| 48 | 48 | }, array_values($elements))); |
| 49 | 49 | |
| 50 | 50 | $this->db->begin(); |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $lasterror = $this->db->lasterror(); |
| 55 | 55 | dol_syslog(__METHOD__ . ' ' . $lasterror, LOG_ERR); |
| 56 | 56 | $this->db->rollback(); |
| 57 | - throw new \Exception("Repository error - ".$lasterror); |
|
| 57 | + throw new \Exception("Repository error - " . $lasterror); |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | $id = $this->db->last_insert_id($this->tableName); |
@@ -31,9 +31,9 @@ discard block |
||
| 31 | 31 | public function __invoke($flightId) |
| 32 | 32 | { |
| 33 | 33 | $sql = 'SELECT damage.amount, author.login as author_name'; |
| 34 | - $sql.=' FROM '.MAIN_DB_PREFIX.'bbc_flight_damages as damage'; |
|
| 35 | - $sql.=' INNER JOIN '.MAIN_DB_PREFIX.'user as author ON author.rowid = damage.author_id'; |
|
| 36 | - $sql.=' WHERE damage.flight_id = '.$this->db->escape($flightId); |
|
| 34 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'bbc_flight_damages as damage'; |
|
| 35 | + $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'user as author ON author.rowid = damage.author_id'; |
|
| 36 | + $sql .= ' WHERE damage.flight_id = ' . $this->db->escape($flightId); |
|
| 37 | 37 | |
| 38 | 38 | $damages = []; |
| 39 | 39 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | if ($resql) { |
| 42 | 42 | $num = $this->db->num_rows($resql); |
| 43 | 43 | if ($num) { |
| 44 | - for($i = 0; $i < $num ; $i++) { |
|
| 44 | + for ($i = 0; $i < $num; $i++) { |
|
| 45 | 45 | $properties = $this->db->fetch_array($resql); |
| 46 | 46 | $damages[] = Damage::fromArray($properties); |
| 47 | 47 | } |
@@ -30,10 +30,10 @@ discard block |
||
| 30 | 30 | public function query($year) |
| 31 | 31 | { |
| 32 | 32 | $sql = 'SELECT SUM(damage.amount) as total_amount, damage.author_id as author'; |
| 33 | - $sql.=' FROM '.MAIN_DB_PREFIX.'bbc_flight_damages as damage'; |
|
| 34 | - $sql.=' INNER JOIN '.MAIN_DB_PREFIX.'bbc_vols as flight ON flight.rowid = damage.flight_id'; |
|
| 35 | - $sql.=' WHERE YEAR(flight.date) = '.$this->db->escape($year); |
|
| 36 | - $sql.=' GROUP BY damage.author_id'; |
|
| 33 | + $sql .= ' FROM ' . MAIN_DB_PREFIX . 'bbc_flight_damages as damage'; |
|
| 34 | + $sql .= ' INNER JOIN ' . MAIN_DB_PREFIX . 'bbc_vols as flight ON flight.rowid = damage.flight_id'; |
|
| 35 | + $sql .= ' WHERE YEAR(flight.date) = ' . $this->db->escape($year); |
|
| 36 | + $sql .= ' GROUP BY damage.author_id'; |
|
| 37 | 37 | |
| 38 | 38 | $damages = []; |
| 39 | 39 | |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | if ($resql) { |
| 42 | 42 | $num = $this->db->num_rows($resql); |
| 43 | 43 | if ($num) { |
| 44 | - for($i = 0; $i < $num ; $i++) { |
|
| 44 | + for ($i = 0; $i < $num; $i++) { |
|
| 45 | 45 | $properties = $this->db->fetch_array($resql); |
| 46 | 46 | $damages[] = TotalDamage::fromArray($properties); |
| 47 | 47 | } |
@@ -87,7 +87,7 @@ discard block |
||
| 87 | 87 | */ |
| 88 | 88 | public function add(FormElementInterface $element) |
| 89 | 89 | { |
| 90 | - if(array_key_exists($element->getName(), $this->elements)){ |
|
| 90 | + if (array_key_exists($element->getName(), $this->elements)) { |
|
| 91 | 91 | throw new \InvalidArgumentException('Element already exists'); |
| 92 | 92 | } |
| 93 | 93 | $this->elements[$element->getName()] = $element; |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | */ |
| 142 | 142 | public function getErrorMessages() |
| 143 | 143 | { |
| 144 | - if(!$this->validator){ |
|
| 144 | + if (!$this->validator) { |
|
| 145 | 145 | return []; |
| 146 | 146 | } |
| 147 | 147 | |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | * |
| 25 | 25 | * @return Id |
| 26 | 26 | */ |
| 27 | - public static function create($id){ |
|
| 27 | + public static function create($id) { |
|
| 28 | 28 | return new self($id); |
| 29 | 29 | } |
| 30 | 30 | |
@@ -33,10 +33,10 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | private function __construct(FlightId $flightId, DamageAmount $amount, $billed, AuthorId $authorId) |
| 35 | 35 | { |
| 36 | - $this->flight = $flightId; |
|
| 37 | - $this->amount = $amount; |
|
| 38 | - $this->billed = $billed; |
|
| 39 | - $this->author = $authorId; |
|
| 36 | + $this->flight = $flightId; |
|
| 37 | + $this->amount = $amount; |
|
| 38 | + $this->billed = $billed; |
|
| 39 | + $this->author = $authorId; |
|
| 40 | 40 | } |
| 41 | 41 | |
| 42 | 42 | /** |
@@ -46,7 +46,7 @@ discard block |
||
| 46 | 46 | * |
| 47 | 47 | * @return FlightDamage |
| 48 | 48 | */ |
| 49 | - public static function damage(FlightId $flightId, DamageAmount $amount, AuthorId $authorId){ |
|
| 49 | + public static function damage(FlightId $flightId, DamageAmount $amount, AuthorId $authorId) { |
|
| 50 | 50 | return new self($flightId, $amount, false, $authorId); |
| 51 | 51 | } |
| 52 | 52 | |
@@ -61,14 +61,14 @@ discard block |
||
| 61 | 61 | /** |
| 62 | 62 | * @return FlightId |
| 63 | 63 | */ |
| 64 | - public function getFlightId(){ |
|
| 64 | + public function getFlightId() { |
|
| 65 | 65 | return $this->flight; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
| 69 | 69 | * @return DamageAmount |
| 70 | 70 | */ |
| 71 | - public function amount(){ |
|
| 71 | + public function amount() { |
|
| 72 | 72 | return $this->amount; |
| 73 | 73 | } |
| 74 | 74 | |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @return array |
| 54 | 54 | */ |
| 55 | 55 | public function toArray() { |
| 56 | - return array_map(function(Tab $tab){ |
|
| 56 | + return array_map(function(Tab $tab) { |
|
| 57 | 57 | return $tab->toArray(); |
| 58 | 58 | }, $this->tabs); |
| 59 | 59 | } |