NetworkPost::getTitle()   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 network post model class.
26
 *
27
 * @author Beñat Espiña <[email protected]>
28
 */
29
class NetworkPost implements Model
30
{
31
    const POST_TYPES = ['question', 'answer'];
32
33
    protected $id;
34
    protected $postType;
35
    protected $score;
36
    protected $title;
37
38
    public static function fromProperties($id, $postType, $score, $title)
39
    {
40
        $instance = new self();
41
        $instance
42
            ->setId($id)
43
            ->setPostType($postType)
44
            ->setScore($score)
45
            ->setTitle($title);
46
47
        return $instance;
48
    }
49
50
    public static function fromJson(array $data)
51
    {
52
        $instance = new self();
53
        $instance
54
            ->setId(array_key_exists('post_id', $data) ? $data['post_id'] : null)
55
            ->setPostType(array_key_exists('post_type', $data) ? $data['post_type'] : null)
56
            ->setScore(array_key_exists('score', $data) ? $data['score'] : null)
57
            ->setTitle(array_key_exists('title', $data) ? $data['title'] : null);
58
59
        return $instance;
60
    }
61
62
    public function getId()
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...
63
    {
64
        return $this->id;
65
    }
66
67
    public function setId($id)
68
    {
69
        $this->id = $id;
70
71
        return $this;
72
    }
73
74
    public function getPostType()
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...
75
    {
76
        return $this->postType;
77
    }
78
79
    public function setPostType($postType)
80
    {
81
        if (in_array($postType, self::POST_TYPES, true)) {
82
            $this->postType = $postType;
83
        }
84
85
        return $this;
86
    }
87
88
    public function getScore()
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...
89
    {
90
        return $this->score;
91
    }
92
93
    public function setScore($score)
94
    {
95
        $this->score = $score;
96
97
        return $this;
98
    }
99
100
    public function getTitle()
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...
101
    {
102
        return $this->title;
103
    }
104
105
    public function setTitle($title)
106
    {
107
        $this->title = $title;
108
109
        return $this;
110
    }
111
}
112