Completed
Push — master ( 61852c...9e945f )
by Joschi
05:39
created

ArticleObjectMutator   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 116
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 116
ccs 23
cts 23
cp 1
rs 10
wmc 8
lcom 1
cbo 4

8 Methods

Rating   Name   Duplication   Size   Complexity  
B initialize() 0 30 1
A mutate() 0 5 1
A setTitle() 0 4 1
A setDescription() 0 4 1
A setAbstract() 0 4 1
A setKeywords() 0 4 1
A setCategories() 0 4 1
A setAuthors() 0 4 1
1
<?php
2
3
/**
4
 * apparat-dev
5
 *
6
 * @category    Apparat
7
 * @package     Apparat\Dev
8
 * @subpackage  Apparat\Dev\Infrastructure
9
 * @author      Joschi Kuphal <[email protected]> / @jkphl
10
 * @copyright   Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
11
 * @license     http://opensource.org/licenses/MIT The MIT License (MIT)
12
 */
13
14
/***********************************************************************************
15
 *  The MIT License (MIT)
16
 *
17
 *  Copyright © 2016 Joschi Kuphal <[email protected]> / @jkphl
18
 *
19
 *  Permission is hereby granted, free of charge, to any person obtaining a copy of
20
 *  this software and associated documentation files (the "Software"), to deal in
21
 *  the Software without restriction, including without limitation the rights to
22
 *  use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
23
 *  the Software, and to permit persons to whom the Software is furnished to do so,
24
 *  subject to the following conditions:
25
 *
26
 *  The above copyright notice and this permission notice shall be included in all
27
 *  copies or substantial portions of the Software.
28
 *
29
 *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30
 *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
31
 *  FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
32
 *  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
33
 *  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
34
 *  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
35
 ***********************************************************************************/
36
37
namespace Apparat\Dev\Infrastructure\Mutator;
38
39
use Apparat\Dev\Application\Utility\Random;
40
use Apparat\Object\Domain\Model\Object\ObjectInterface;
41
42
/**
43
 * Article object mutator
44
 *
45
 * @package Apparat\Dev
46
 * @subpackage Apparat\Dev\Infrastructure
47
 * @method ObjectInterface setRandomDescription(ObjectInterface $object, $probability)
48
 * @method ObjectInterface setRandomAbstract(ObjectInterface $object, $probability)
49
 * @method ObjectInterface setRandomCategories(ObjectInterface $object, $probability)
50
 * @method ObjectInterface setRandomKeywords(ObjectInterface $object, $probability)
51
 */
52
class ArticleObjectMutator extends AbstractObjectMutator
53
{
54
    /**
55
     * Initialize the article
56
     *
57
     * @param ObjectInterface $object Article
58
     * @return ObjectInterface Article
59
     */
60 1
    public function initialize(ObjectInterface $object)
61
    {
62 1
        $this->setTitle($object); // p-name
63 1
        $this->setRandomDescription($object, .7); // p-summary
64 1
        $this->setRandomAbstract($object, .2);
65 1
        $this->setRandomCategories($object, .4); // p-category
66 1
        $this->setRandomKeywords($object, .7);
67 1
        $this->setAuthors($object); // TODO p-author
0 ignored issues
show
Unused Code introduced by
The call to the method Apparat\Dev\Infrastructu...ctMutator::setAuthors() seems un-needed as the method has no side-effects.

PHP Analyzer performs a side-effects analysis of your code. A side-effect is basically anything that might be visible after the scope of the method is left.

Let’s take a look at an example:

class User
{
    private $email;

    public function getEmail()
    {
        return $this->email;
    }

    public function setEmail($email)
    {
        $this->email = $email;
    }
}

If we look at the getEmail() method, we can see that it has no side-effect. Whether you call this method or not, no future calls to other methods are affected by this. As such code as the following is useless:

$user = new User();
$user->getEmail(); // This line could safely be removed as it has no effect.

On the hand, if we look at the setEmail(), this method _has_ side-effects. In the following case, we could not remove the method call:

$user = new User();
$user->setEmail('email@domain'); // This line has a side-effect (it changes an
                                 // instance variable).
Loading history...
68
69
        // URL = u-url
70
        // URL = u-uid
71
        // system.published = dt-published
72
        // system.modified = dt-updated
73
74
        // p-location
75
        // u-syndication
76
        // u-in-reply-to
77
        // p-rsvp
78
        // p-comment
79
        // u-like-of
80
        // u-like
81
        // u-repost-of
82
        // u-repost (+ h-cite)
83
        // u-photo
84
        // u-audio
85
        // u-video
86
        // u-featured
87
88 1
        return $object;
89
    }
90
91
    /**
92
     * Mutate the article
93
     *
94
     * @param ObjectInterface $object Article
95
     * @return ObjectInterface Article
96
     */
97 1
    public function mutate(ObjectInterface $object)
98
    {
99 1
        $object->setPayload(Random::markdown()); // e-content
100 1
        return $object;
101
    }
102
103
    /**
104
     * Set the article title
105
     *
106
     * @param ObjectInterface $object Article
107
     * @return ObjectInterface $object Article
108
     */
109 1
    protected function setTitle(ObjectInterface $object)
110
    {
111 1
        return $object->setTitle($this->generator->text(70));
112
    }
113
    /**
114
     * Set the article description
115
     *
116
     * @param ObjectInterface $object Article
117
     * @return ObjectInterface $object Article
118
     */
119 1
    protected function setDescription(ObjectInterface $object)
120
    {
121 1
        return $object->setDescription($this->generator->text(200));
122
    }
123
124
    /**
125
     * Set the article abstract
126
     *
127
     * @param ObjectInterface $object Article
128
     * @return ObjectInterface $object Article
129
     */
130 1
    protected function setAbstract(ObjectInterface $object)
131
    {
132 1
        return $object->setAbstract($this->generator->realText(250));
133
    }
134
135
    /**
136
     * Set the article keywords
137
     *
138
     * @param ObjectInterface $object Article
139
     * @return ObjectInterface $object Article
140
     */
141 1
    protected function setKeywords(ObjectInterface $object)
142
    {
143 1
        return $object->setKeywords($this->generator->words(rand(0, 5)));
0 ignored issues
show
Bug introduced by
It seems like $this->generator->words(rand(0, 5)) targeting Faker\Generator::words() can also be of type string; however, Apparat\Object\Domain\Mo...nterface::setKeywords() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
144
    }
145
146
    /**
147
     * Set the article categories
148
     *
149
     * @param ObjectInterface $object Article
150
     * @return ObjectInterface $object Article
151
     */
152 1
    protected function setCategories(ObjectInterface $object)
153
    {
154 1
        return $object->setCategories($this->generator->words(rand(0, 5)));
0 ignored issues
show
Bug introduced by
It seems like $this->generator->words(rand(0, 5)) targeting Faker\Generator::words() can also be of type string; however, Apparat\Object\Domain\Mo...erface::setCategories() does only seem to accept array, maybe add an additional type check?

This check looks at variables that are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
155
    }
156
157
    /**
158
     * Set the article authors
159
     *
160
     * @param ObjectInterface $object Article
161
     * @return ObjectInterface $object Article
162
     */
163 1
    protected function setAuthors(ObjectInterface $object)
164
    {
165 1
        return $object;
166
    }
167
}