| Conditions | 6 |
| Paths | 6 |
| Total Lines | 29 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | public function findAll(): ?array |
||
| 38 | { |
||
| 39 | if($this->all){ |
||
| 40 | return $this->all; |
||
| 41 | } |
||
| 42 | |||
| 43 | |||
| 44 | $resource=file_get_contents($this->url->__toString()); |
||
| 45 | if(empty($resource)){ |
||
| 46 | return null; |
||
| 47 | } |
||
| 48 | |||
| 49 | try{ |
||
| 50 | $resource=json_decode($resource,true); |
||
| 51 | if(!$resource){ |
||
| 52 | return null; |
||
| 53 | } |
||
| 54 | }catch (\Exception $e){ |
||
| 55 | return null; |
||
| 56 | } |
||
| 57 | foreach ($resource as $item){ |
||
| 58 | $this->all[]=new RegionBranch( |
||
| 59 | (int)$item['id'], |
||
| 60 | $item['origName'], |
||
| 61 | $item['newName'] |
||
| 62 | ); |
||
| 63 | } |
||
| 64 | return $this->all; |
||
| 65 | } |
||
| 66 | |||
| 91 | } |
There are different options of fixing this problem.
If you want to be on the safe side, you can add an additional type-check:
If you are sure that the expression is traversable, you might want to add a doc comment cast to improve IDE auto-completion and static analysis:
Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.