Sf4 /
Api
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * Created by PhpStorm. |
||
| 4 | * User: siim |
||
| 5 | * Date: 18.02.19 |
||
| 6 | * Time: 9:06 |
||
| 7 | */ |
||
| 8 | |||
| 9 | namespace Sf4\Api\RequestHandler\Traits; |
||
| 10 | |||
| 11 | use Sf4\Api\DependencyInjection\Configuration; |
||
| 12 | |||
| 13 | trait SitesTrait |
||
| 14 | { |
||
| 15 | /** @var array|null $sites */ |
||
| 16 | protected $sites = []; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @return array|null |
||
| 20 | */ |
||
| 21 | public function getSites(): ?array |
||
| 22 | { |
||
| 23 | return $this->sites; |
||
| 24 | } |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @param array|null $sites |
||
| 28 | */ |
||
| 29 | public function setSites(?array $sites): void |
||
| 30 | { |
||
| 31 | $this->sites = $sites; |
||
| 32 | } |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @param array|null $sites |
||
| 36 | */ |
||
| 37 | public function addSites(?array $sites): void |
||
| 38 | { |
||
| 39 | if (!$sites) { |
||
|
0 ignored issues
–
show
|
|||
| 40 | return ; |
||
| 41 | } |
||
| 42 | |||
| 43 | foreach ($sites as $site) { |
||
| 44 | $this->addSite($site); |
||
| 45 | } |
||
| 46 | } |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @param array $site |
||
| 50 | */ |
||
| 51 | public function addSite(array $site): void |
||
| 52 | { |
||
| 53 | if (isset( |
||
| 54 | $site[Configuration::SITES_SITE], |
||
| 55 | $site[Configuration::SITES_URL], |
||
| 56 | $site[Configuration::SITES_TOKEN] |
||
| 57 | )) { |
||
| 58 | foreach ($this->sites as $thisSite) { |
||
| 59 | if ($thisSite[Configuration::SITES_SITE] === $site[Configuration::SITES_SITE]) { |
||
| 60 | return ; |
||
| 61 | } |
||
| 62 | } |
||
| 63 | $this->sites[] = $site; |
||
| 64 | } |
||
| 65 | } |
||
| 66 | } |
||
| 67 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.