Test Failed
Push — feature-laravel-5.4 ( 475d96...446986 )
by Kirill
07:30
created

ExternalArticle::getTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * This file is part of laravel.su package.
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
declare(strict_types=1);
8
9
namespace App\Services\DataProviders;
10
11
use App\Models\Article;
12
use Carbon\Carbon;
13
use Illuminate\Contracts\Support\Arrayable;
14
15
/**
16
 * Class ExternalArticle.
17
 */
18
class ExternalArticle implements Arrayable
19
{
20
    /**
21
     * @var string
22
     */
23
    private $title;
24
25
    /**
26
     * @var string
27
     */
28
    private $body;
29
30
    /**
31
     * @var string
32
     */
33
    private $url;
34
35
    /**
36
     * @var \DateTime
37
     */
38
    private $createdAt;
39
40
    /**
41
     * @var array|string[]
42
     */
43
    private $images = [];
44
45
    /**
46
     * ExternalArticle constructor.
47
     * @param string $title
48
     * @param string $body
49
     * @param string $url
50
     */
51
    public function __construct(string $title, string $body, string $url)
52
    {
53
        $this->title = $title;
54
        $this->body = $body;
55
        $this->url = $url;
56
57
        $this->createdAt = Carbon::now();
58
    }
59
60
    /**
61
     * @param string $image
62
     * @return $this
63
     */
64
    public function addImageUrl(string $image)
65
    {
66
        $this->images[] = $image;
67
68
        return $this;
69
    }
70
71
    /**
72
     * @return array
73
     */
74
    public function getImages(): array
75
    {
76
        return [];
77
    }
78
79
    /**
80
     * @return string
81
     */
82
    public function getTitle(): string
83
    {
84
        return $this->title;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    public function getBody(): string
91
    {
92
        return $this->body;
93
    }
94
95
    /**
96
     * @return string
97
     */
98
    public function getUrl(): string
99
    {
100
        return $this->url;
101
    }
102
103
    /**
104
     * @return \DateTime
105
     */
106
    public function getCreatedAt(): \DateTime
107
    {
108
        return $this->createdAt;
109
    }
110
111
    /**
112
     * @param \DateTime $createdAt
113
     * @return $this|ExternalArticle
114
     */
115
    public function setCreatedAt(\DateTime $createdAt)
116
    {
117
        $this->createdAt = $createdAt;
118
119
        return $this;
120
    }
121
122
    /**
123
     * @return array
124
     */
125
    public function toArray(): array
126
    {
127
        return [
128
            'title'      => $this->title,
129
            'url'        => $this->url,
130
            'images'     => $this->images,
131
            'content'    => $this->body,
132
            'created_at' => $this->createdAt,
133
        ];
134
    }
135
136
    /**
137
     * @param Article $article
138
     * @return Article
139
     */
140
    public function fill(Article $article): Article
141
    {
142
        $article->title = $this->title;
0 ignored issues
show
Documentation introduced by
The property title does not exist on object<App\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
143
        //$article-
144
        $article->image = reset($this->images);
0 ignored issues
show
Documentation introduced by
The property image does not exist on object<App\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
145
146
        $article->content_source   = '';
0 ignored issues
show
Documentation introduced by
The property content_source does not exist on object<App\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
147
        $article->content_rendered = $this->body;
0 ignored issues
show
Documentation introduced by
The property content_rendered does not exist on object<App\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
148
149
        $article->published_at = $this->createdAt;
0 ignored issues
show
Documentation introduced by
The property published_at does not exist on object<App\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
150
151
        $article->status = Article\Status::PUBLISHED;
0 ignored issues
show
Documentation introduced by
The property status does not exist on object<App\Models\Article>. Since you implemented __set, maybe consider adding a @property annotation.

Since your code implements the magic setter _set, this function will be called for any write access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

Since the property has write access only, you can use the @property-write annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
152
153
        return $article;
154
    }
155
}