Completed
Push — v2 ( aabbd0...b8f0e3 )
by Beñat
07:15
created

ClosedDetails::getByUsers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 2
Metric Value
c 3
b 0
f 2
dl 0
loc 4
rs 10
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
 * Copyright (c) 2014-2016 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
namespace BenatEspina\StackExchangeApiClient\Model;
13
14
/**
15
 * The close details model class.
16
 *
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
class CloseDetails implements Model
20
{
21
    protected $byUsers;
22
    protected $description;
23
    protected $onHold;
24
    protected $originalQuestions;
25
    protected $reason;
26
27
    public static function fromProperties(
28
        array $byUsers,
29
        $description,
30
        $onHold,
31
        array $originalQuestions,
32
        $reason
33
    ) {
34
        $instance = new self();
35
        $instance
36
            ->setByUsers($byUsers)
37
            ->setDescription($description)
38
            ->setOnHold($onHold)
39
            ->setOriginalQuestions($originalQuestions)
40
            ->setReason($reason);
41
42
        return $instance;
43
    }
44
45
    public static function fromJson(array $data)
46
    {
47
        $instance = new self();
48
49
        $byUsers = [];
50 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...
51
            foreach ($data['by_users'] as $byUser) {
52
                $byUsers[] = ShallowUser::fromJson($byUser);
53
            }
54
        }
55
        $originalQuestions = [];
56 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...
57
            foreach ($data['original_questions'] as $originalQuestion) {
58
                $originalQuestions[] = ShallowUser::fromJson($originalQuestion);
59
            }
60
        }
61
62
        $instance
0 ignored issues
show
Bug introduced by
The method setCanFlag() does not seem to exist on object<BenatEspina\Stack...ent\Model\CloseDetails>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
63
            ->setByUsers($byUsers)
64
            ->setDescription(array_key_exists('description', $data) ? $data['description'] : null)
65
            ->setOnHold(array_key_exists('on_hold', $data) ? $data['on_hold'] : null)
66
            ->setOriginalQuestions($originalQuestions)
67
            ->setCanFlag(array_key_exists('reason', $data) ? $data['reason'] : null);
68
69
        return $instance;
70
    }
71
72
    public function setByUsers(array $byUsers = [])
73
    {
74
        $this->byUsers = $byUsers;
75
76
        return $this;
77
    }
78
79
    public function getByUsers()
80
    {
81
        return $this->byUsers;
82
    }
83
84
    public function setDescription($description)
85
    {
86
        $this->description = $description;
87
88
        return $this;
89
    }
90
91
    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...
92
    {
93
        return $this->description;
94
    }
95
96
    public function setOnHold($onHold)
97
    {
98
        $this->onHold = $onHold;
99
100
        return $this;
101
    }
102
103
    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...
104
    {
105
        return $this->onHold;
106
    }
107
108
    public function setOriginalQuestions(array $originalQuestions = [])
109
    {
110
        $this->originalQuestions = $originalQuestions;
111
112
        return $this;
113
    }
114
115
    public function getOriginalQuestions()
116
    {
117
        return $this->originalQuestions;
118
    }
119
120
    public function setReason($reason)
121
    {
122
        $this->reason = $reason;
123
124
        return $this;
125
    }
126
127
    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...
128
    {
129
        return $this->reason;
130
    }
131
}
132