|
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 |
|
|
|
|
|
|
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))); |
|
|
|
|
|
|
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))); |
|
|
|
|
|
|
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
|
|
|
} |
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:
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: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: