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.

Cardwall_SingleCard   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5
Metric Value
wmc 12
lcom 1
cbo 5
dl 0
loc 91
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getCardInCellPresenter() 0 3 1
A getColumnId() 0 3 1
A getFields() 0 3 1
A getFieldById() 0 11 4
A getArtifact() 0 3 1
A getFieldJsonValue() 0 3 1
A getFieldHTMLValue() 0 3 1
A getMapping() 0 3 1
A __construct() 0 14 1
1
<?php
2
/**
3
 * Copyright (c) Enalean, 2013. 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
21
/**
22
 * This class is a wrapper on top of card in cell presenter to be used when
23
 * a card is rendered out of the board context.
24
 *
25
 * In other words it's what you need when you only want to have one single card
26
 */
27
class Cardwall_SingleCard {
28
29
    /** @var Cardwall_CardInCellPresenter */
30
    private $card_in_cell_presenter;
31
32
    /** @var Tracker_Artifact */
33
    private $artifact;
34
35
    /** @var Cardwall_CardFields */
36
    private $card_fields;
37
38
    /** @var Cardwall_UserPreferences_UserPreferencesDisplayUser */
39
    private $display_preferences;
40
41
    /** @var int */
42
    private $column_id;
43
44
    /** @var Cardwall_OnTop_Config_TrackerMapping */
45
    private $mapping;
46
47
    /** @var array */
48
    private $fields_cache = null;
49
50
    public function __construct(
51
        Cardwall_CardInCellPresenter $card_in_cell_presenter,
52
        Cardwall_CardFields $card_fields,
53
        Cardwall_UserPreferences_UserPreferencesDisplayUser $display_preferences,
54
        $column_id,
55
        Cardwall_OnTop_Config_TrackerMapping $mapping
56
    ) {
57
        $this->card_in_cell_presenter = $card_in_cell_presenter;
58
        $this->artifact               = $card_in_cell_presenter->getArtifact();
59
        $this->card_fields            = $card_fields;
60
        $this->display_preferences    = $display_preferences;
61
        $this->column_id              = $column_id;
62
        $this->mapping                = $mapping;
63
    }
64
65
    /**
66
     * @return Cardwall_CardInCellPresenter
67
     */
68
    public function getCardInCellPresenter() {
69
        return $this->card_in_cell_presenter;
70
    }
71
72
    public function getColumnId() {
73
        return $this->column_id;
74
    }
75
76
    public function getFields() {
77
        return $this->card_fields->getFields($this->artifact);
78
    }
79
80
    /**
81
     * Return a field on the card based on the card
82
     *
83
     * @param Integer $id
84
     *
85
     * @return Tracker_FormElement_Field
86
     */
87
    public function getFieldById($id) {
88
        if ($this->fields_cache === null) {
89
            foreach ($this->getFields() as $field) {
90
                $this->fields_cache[$field->getId()] = $field;
91
            }
92
        }
93
        if (isset($this->fields_cache[$id])) {
94
            return $this->fields_cache[$id];
95
        }
96
        throw new Cardwall_FieldNotOnCardException($id);
97
    }
98
99
    /**
100
     * @return Tracker_Artifact
101
     */
102
    public function getArtifact() {
103
        return $this->artifact;
104
    }
105
106
    public function getFieldJsonValue(PFUser $user, Tracker_FormElement_Field $field) {
107
        return $field->getJsonValue($user, $this->artifact->getLastChangeset());
0 ignored issues
show
Bug introduced by
It seems like $this->artifact->getLastChangeset() can be null; however, getJsonValue() does not accept null, maybe add an additional type check?

Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code:

/** @return stdClass|null */
function mayReturnNull() { }

function doesNotAcceptNull(stdClass $x) { }

// With potential error.
function withoutCheck() {
    $x = mayReturnNull();
    doesNotAcceptNull($x); // Potential error here.
}

// Safe - Alternative 1
function withCheck1() {
    $x = mayReturnNull();
    if ( ! $x instanceof stdClass) {
        throw new \LogicException('$x must be defined.');
    }
    doesNotAcceptNull($x);
}

// Safe - Alternative 2
function withCheck2() {
    $x = mayReturnNull();
    if ($x instanceof stdClass) {
        doesNotAcceptNull($x);
    }
}
Loading history...
108
    }
109
110
    public function getFieldHTMLValue(PFUser $user, Tracker_FormElement_Field $field) {
111
        return $field->fetchCardValue($this->artifact, $this->display_preferences);
112
    }
113
114
    public function getMapping() {
115
        return $this->mapping;
116
    }
117
}
118