CloseDetails::getReason()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
/*
4
 * This file is part of the Stack Exchange Api Client library.
5
 *
6
 * (c) Beñat Espiña <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
declare(strict_types=1);
13
/*
14
 * This file is part of the Stack Exchange Api Client library.
15
 *
16
 * (c) Beñat Espiña <[email protected]>
17
 *
18
 * For the full copyright and license information, please view the LICENSE
19
 * file that was distributed with this source code.
20
 */
21
22
namespace BenatEspina\StackExchangeApiClient\Model;
23
24
/**
25
 * The close details model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class CloseDetails implements Model
30
{
31
    protected $byUsers;
32
    protected $description;
33
    protected $onHold;
34
    protected $originalQuestions;
35
    protected $reason;
36
37
    public static function fromProperties(
38
        array $byUsers,
39
        $description,
40
        $onHold,
41
        array $originalQuestions,
42
        $reason
43
    ) {
44
        $instance = new self();
45
        $instance
46
            ->setByUsers($byUsers)
47
            ->setDescription($description)
48
            ->setOnHold($onHold)
49
            ->setOriginalQuestions($originalQuestions)
50
            ->setReason($reason);
51
52
        return $instance;
53
    }
54
55
    public static function fromJson(array $data)
56
    {
57
        $instance = new self();
58
59
        $byUsers = [];
60 View Code Duplication
        if (array_key_exists('by_users', $data) && is_array($data['by_users'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
61
            foreach ($data['by_users'] as $byUser) {
62
                $byUsers[] = ShallowUser::fromJson($byUser);
63
            }
64
        }
65
        $originalQuestions = [];
66 View Code Duplication
        if (array_key_exists('original_questions', $data) && is_array($data['original_questions'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
67
            foreach ($data['original_questions'] as $originalQuestion) {
68
                $originalQuestions[] = ShallowUser::fromJson($originalQuestion);
69
            }
70
        }
71
72
        $instance
73
            ->setByUsers($byUsers)
74
            ->setDescription(array_key_exists('description', $data) ? $data['description'] : null)
75
            ->setOnHold(array_key_exists('on_hold', $data) ? $data['on_hold'] : null)
76
            ->setOriginalQuestions($originalQuestions)
77
            ->setCanFlag(array_key_exists('reason', $data) ? $data['reason'] : null);
78
79
        return $instance;
80
    }
81
82
    public function setByUsers(array $byUsers = [])
83
    {
84
        $this->byUsers = $byUsers;
85
86
        return $this;
87
    }
88
89
    public function getByUsers()
90
    {
91
        return $this->byUsers;
92
    }
93
94
    public function setDescription($description)
95
    {
96
        $this->description = $description;
97
98
        return $this;
99
    }
100
101
    public function getDescription()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
102
    {
103
        return $this->description;
104
    }
105
106
    public function setOnHold($onHold)
107
    {
108
        $this->onHold = $onHold;
109
110
        return $this;
111
    }
112
113
    public function isOnHold()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
114
    {
115
        return $this->onHold;
116
    }
117
118
    public function setOriginalQuestions(array $originalQuestions = [])
119
    {
120
        $this->originalQuestions = $originalQuestions;
121
122
        return $this;
123
    }
124
125
    public function getOriginalQuestions()
126
    {
127
        return $this->originalQuestions;
128
    }
129
130
    public function setReason($reason)
131
    {
132
        $this->reason = $reason;
133
134
        return $this;
135
    }
136
137
    public function getReason()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
138
    {
139
        return $this->reason;
140
    }
141
}
142