GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.

NewsItemForWidgetDataMapper::fetchAll()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
1
<?php
2
/**
3
  * Copyright (c) Enalean, 2014. All rights reserved
4
  *
5
  * This file is a part of Tuleap.
6
  *
7
  * Tuleap is free software; you can redistribute it and/or modify
8
  * it under the terms of the GNU General Public License as published by
9
  * the Free Software Foundation; either version 2 of the License, or
10
  * (at your option) any later version.
11
  *
12
  * Tuleap is distributed in the hope that it will be useful,
13
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
  * GNU General Public License for more details.
16
  *
17
  * You should have received a copy of the GNU General Public License
18
  * along with Tuleap. If not, see <http://www.gnu.org/licenses/
19
  */
20
 class NewsItemForWidgetDataMapper {
21
22
    /**
23
    * @var NewsItemForWidgetDao $dao
24
    */
25
    private $dao;
26
27
    public function __construct(NewsItemForWidgetDao $dao) {
28
        $this->dao = $dao;
29
    }
30
31
    /**
32
     * @return NewsItem[]
33
     */
34
    public function fetchAll(Project $project) {
35
        $rows = $this->dao->fetchAll($project->getID());
36
37
        $items = array();
38
        foreach ($rows as $row) {
0 ignored issues
show
Bug introduced by
The expression $rows of type false|object is not guaranteed to be traversable. How about adding an additional type check?

There are different options of fixing this problem.

  1. If you want to be on the safe side, you can add an additional type-check:

    $collection = json_decode($data, true);
    if ( ! is_array($collection)) {
        throw new \RuntimeException('$collection must be an array.');
    }
    
    foreach ($collection as $item) { /** ... */ }
    
  2. 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:

    /** @var array $collection */
    $collection = json_decode($data, true);
    
    foreach ($collection as $item) { /** .. */ }
    
  3. Mark the issue as a false-positive: Just hover the remove button, in the top-right corner of this issue for more options.

Loading history...
39
            $items[] = new NewsItem($row);
40
        }
41
42
        return $items;;
43
    }
44
45
    public function updatePromotedItems(Project $project, $promoted_ids) {
46
        $this->dao->updatePromotedItems((array) $promoted_ids, $project->getID());
47
    }
48
}
49