Passed
Push — develop ( fc7043...b7cd40 )
by Jens
02:53
created

JsonStorage::createBrickFromPostValues()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 24
Code Lines 18

Duplication

Lines 12
Ratio 50 %

Importance

Changes 0
Metric Value
cc 4
eloc 18
nc 3
nop 1
dl 12
loc 24
rs 8.6845
c 0
b 0
f 0
1
<?php
2
namespace library\storage
3
{
4
5
    use library\crypt\Crypt;
6
    use library\images\ImageResizer;
7
8
    /**
9
	 * Class JsonStorage
10
	 * @package library\storage
11
	 */
12
	class JsonStorage implements Storage
13
	{
14
		private $storageDir;
15
        /**
16
         * @var Repository
17
         */
18
		private $repository;
19
20
		/**
21
		 * JsonStorage constructor.
22
		 *
23
		 * @param $storageDir
24
		 */
25
		public function __construct($storageDir)
26
		{
27
			$this->storageDir = $storageDir;
28
			$this->config();
29
		}
30
31
		/**
32
		 * Retrieve the data from the storagepath
33
		 * so it can be interacted with
34
		 *
35
		 * @throws \Exception
36
		 */
37
		private function config()
38
		{
39
			$storagePath = __DIR__ . '/../../' . $this->storageDir;
40
			if (realpath($storagePath) === false) {
41
				initFramework($storagePath);
42
				if (Repository::create($storagePath)) {
43
					$repository = new Repository($storagePath);
44
					$repository->init();
45
					$this->repository = $repository;
46
				} else {
47
					throw new \Exception('Could not create repository directory: ' . $storagePath);
48
				}
49
			} else {
50
				$this->repository = new Repository($storagePath);
51
			}
52
53
		}
54
55
56
57
		/**
58
		 * Get user by username
59
		 *
60
		 * @param $username
61
		 *
62
		 * @return array
63
		 */
64 View Code Duplication
		public function getUserByUsername($username)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
65
		{
66
			$return = array();
67
			
68
			$users = $this->repository->users;
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
69
			foreach ($users as $user) {
70
				if ($user->username == $username) {
71
					$return = $user;
72
					break;
73
				}
74
			}
75
			
76
			return $return;
77
		}
78
79 View Code Duplication
		public function getUserBySlug($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
80
		{
81
			$return = array();
82
83
			$users = $this->repository->users;
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
84
			foreach ($users as $user) {
85
				if ($user->slug == $slug) {
86
					$return = $user;
87
					break;
88
				}
89
			}
90
91
			return $return;
92
		}
93
94
		public function getUsers()
95
		{
96
			return $this->repository->users;
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
97
		}
98
99
		public function saveUser($slug, $postValues)
100
		{
101
			$userObj = $this->createUserFromPostValues($postValues);
102
			if ($userObj->slug != $slug) {
103
				// If the username changed, check for duplicates
104
				$doesItExist = $this->getUserBySlug($userObj->slug);
105
				if (!empty($doesItExist)) {
106
					throw new \Exception('Trying to rename user to existing username');
107
				}
108
			}
109
			$users = $this->getUsers();
110
			foreach ($users as $key => $user) {
111
				if ($user->slug == $slug) {
112
					$users[$key] = $userObj;
113
				}
114
			}
115
			$this->repository->users = $users;
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
116
			$this->save();
117
		}
118
119
		public function addUser($postValues)
120
		{
121
			$userObj = $this->createUserFromPostValues($postValues);
122
123
			$doesItExist = $this->getUserBySlug($userObj->slug);
124
			if (!empty($doesItExist)) {
125
				throw new \Exception('Trying to add username that already exists.');
126
			}
127
            $users = $this->repository->users;
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
128
            $users[] = $userObj;
129
            $this->repository->users = $users;
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
130
			$this->save();
131
		}
132
133
		public function deleteUserBySlug($slug)
134
		{
135
			$userToDelete = $this->getUserBySlug($slug);
136
			if (empty($userToDelete)) {
137
				throw new \Exception('Trying to delete a user that doesn\'t exist.');
138
			}
139
			$users = $this->getUsers();
140
			foreach ($users as $key => $user) {
141
				if ($user->slug == $userToDelete->slug) {
142
					unset($users[$key]);
143
					$this->repository->users = array_values($users);
0 ignored issues
show
Documentation introduced by
The property $users is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
144
				}
145
			}
146
			$this->save();
147
		}
148
149
		private function createUserFromPostValues($postValues)
150
		{
151
			if (isset($postValues['username'])) {
152
				$user = new \stdClass();
153
				$user->username = $postValues['username'];
154
				$user->slug = slugify($postValues['username']);
155
				$user->rights = array();
156
				if (isset($postValues['rights'])) {
157
					$user->rights = $postValues['rights'];
158
				}
159
160
				if (isset($postValues['password']) && empty($postValues['password']) === false) {
161
					$crypt = new Crypt();
162
					$user->password = $crypt->encrypt($postValues['password'], 16);
163
					$user->salt = $crypt->getLastSalt();
164
				} else {
165
					$user->password = $postValues['passHash'];
166
					$user->salt = $postValues['salt'];
167
				}
168
169
				return $user;
170
			} else {
171
				throw new \Exception('Trying to create user with invalid data.');
172
			}
173
		}
174
175
		/*
176
		 *
177
		 * Documents
178
		 *
179
		 */
180
		/**
181
		 * Get documents
182
		 *
183
		 * @return array
184
		 */
185
		public function getDocuments()
186
		{
187
			return $this->repository->getDocuments();
188
		}
189
190
		/**
191
		 * @param string $slug
192
		 * @return mixed
193
		 * @throws \Exception
194
		 */
195
		public function getDocumentBySlug($slug)
196
		{
197
            $path = '/' . $slug;
198
			return $this->repository->getDocumentByPath($path);
199
		}
200
201
		public function saveDocument($postValues)
202
		{
203
            $oldPath = '/' . $postValues['path'];
204
205
            $container = $this->getDocumentContainerByPath($oldPath);
206
            $documentObject = $this->createDocumentFromPostValues($postValues);
207
            if ($container->path === '/') {
208
                $newPath = $container->path . $documentObject->slug;
209
            } else {
210
                $newPath = $container->path . '/' . $documentObject->slug;
211
            }
212
            $documentObject->path = $newPath;
213
            $this->repository->saveDocument($documentObject);
214
        }
215
216 View Code Duplication
		public function addDocument($postValues)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
217
		{
218
			$documentObject = $this->createDocumentFromPostValues($postValues);
219
            if ($postValues['path'] === '/') {
220
                $documentObject->path = $postValues['path'] . $documentObject->slug;
221
            } else {
222
                $documentObject->path = $postValues['path'] . '/' . $documentObject->slug;
223
            }
224
225
            $this->repository->saveDocument($documentObject);
226
		}
227
228
		public function deleteDocumentBySlug($slug)
229
		{
230
            $path = '/' . $slug;
231
			$this->repository->deleteDocumentByPath($path);
232
		}
233
234
		private function createDocumentFromPostValues($postValues)
235
		{
236
			$postValues = utf8Convert($postValues);
237
			$documentType = $this->getDocumentTypeBySlug($postValues['documentType']);
238
239
			$staticBricks = $documentType->bricks;
240
241
			$documentObj = new Document();
242
			$documentObj->title = $postValues['title'];
243
			$documentObj->slug = slugify($postValues['title']);
244
			$documentObj->type = 'document';
245
			$documentObj->documentType = $documentType->title;
246
			$documentObj->documentTypeSlug = $documentType->slug;
247
			$documentObj->state = isset($postValues['state']) ? 'published' : 'unpublished';
248
			$documentObj->lastModificationDate = time();
249
			$documentObj->creationDate = isset($postValues['creationDate']) ? intval($postValues['creationDate']) : time();
250
			$documentObj->lastModifiedBy = $_SESSION['cloudcontrol']->username;
251
252
			$documentObj->fields = isset($postValues['fields']) ? $postValues['fields'] : array();
0 ignored issues
show
Documentation introduced by
The property $fields is declared protected in library\storage\Document. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
253
254
			$documentObj->bricks = array();
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Document. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
255
			if (isset($postValues['bricks'])) {
256
				foreach ($postValues['bricks'] as $brickSlug => $brick) {
257
					// Check if its multiple
258
					$multiple = false;
259
					$staticBrick = null;
260
					foreach ($staticBricks as $staticBrick) {
261
						if ($staticBrick->slug === $brickSlug) {
262
							$multiple = $staticBrick->multiple;
263
							break;
264
						}
265
					}
266
267
					if ($multiple) {
268
						$brickArray = array();
269
						foreach ($brick as $brickInstance) {
270
							$brickObj = new \stdClass();
271
							$brickObj->fields = new \stdClass();
272
							$brickObj->type = $staticBrick->brickSlug;
273
274
							foreach ($brickInstance['fields'] as $fieldName => $fieldValues) {
275
								$brickObj->fields->$fieldName = $fieldValues;
276
							}
277
278
							$brickArray[] = $brickObj;
279
						}
280
281
						$documentObj->bricks[$brickSlug] = $brickArray;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Document. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
282
					} else {
283
						$documentObj->bricks[$brickSlug] = $brick;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Document. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
284
					}
285
				}
286
			}
287
			$documentObj->dynamicBricks = array();
0 ignored issues
show
Documentation introduced by
The property $dynamicBricks is declared protected in library\storage\Document. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
288
			if (isset($postValues['dynamicBricks'])) {
289
				foreach ($postValues['dynamicBricks'] as $brickTypeSlug => $brick) {
290
					foreach ($brick as $brickContent) {
291
						$brickObj = new \stdClass();
292
						$brickObj->type = $brickTypeSlug;
293
						$brickObj->fields = $brickContent;
294
						$documentObj->dynamicBricks[] = $brickObj;
0 ignored issues
show
Documentation introduced by
The property $dynamicBricks is declared protected in library\storage\Document. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
295
					}
296
				}
297
			}
298
			return $documentObj;
299
		}
300
301
		/**
302
		 * Add new document in given path
303
		 *
304
		 * @param array $postValues
305
		 *
306
		 * @throws \Exception
307
		 */
308 View Code Duplication
		public function addDocumentFolder($postValues)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
309
		{
310
            $documentFolderObject = $this->createDocumentFolderFromPostValues($postValues);
311
            if ($postValues['path'] === '/') {
312
                $documentFolderObject->path = $postValues['path'] . $documentFolderObject->slug;
313
            } else {
314
                $documentFolderObject->path = $postValues['path'] . '/' . $documentFolderObject->slug;
315
            }
316
            $this->repository->saveDocument($documentFolderObject);
317
		}
318
319
		/**
320
		 * Delete a folder by its compound slug
321
		 *
322
		 * @param $slug
323
		 *
324
		 * @throws \Exception
325
		 */
326
		public function deleteDocumentFolderBySlug($slug)
327
		{
328
            $path = '/' . $slug;
329
			$this->repository->deleteDocumentByPath($path);
330
		}
331
332
		/**
333
		 * Retrieve a folder by its compound slug
334
		 *
335
		 * @param $slug
336
		 *
337
		 * @return mixed
338
		 * @throws \Exception
339
		 */
340
		public function getDocumentFolderBySlug($slug)
341
		{
342
            $path = '/' . $slug;
343
			return $this->repository->getDocumentByPath($path);
344
		}
345
346
		/**
347
		 * Save changes to folder
348
		 *
349
		 * @param $postValues
350
		 *
351
		 * @throws \Exception
352
		 */
353
		public function saveDocumentFolder($postValues)
354
		{
355
            $this->addDocumentFolder($postValues);
356
		}
357
358
		/**
359
		 * Convert path to indeces
360
		 *
361
		 * @param $path
362
		 *
363
		 * @return array
364
		 * @throws \Exception
365
		 */
366
		private function getDocumentContainerByPath($path)
367
		{
368
            return $this->repository->getDocumentContainerByPath($path);
369
		}
370
371
		/**
372
		 * Create folder from post values
373
		 *
374
		 * @param $postValues
375
		 *
376
		 * @return \stdClass
377
		 * @throws \Exception
378
		 */
379
		private function createDocumentFolderFromPostValues($postValues)
380
		{
381
			if (isset($postValues['title'], $postValues['path'], $postValues['content'])) {
382
				$documentFolderObject = new Document();
383
				$documentFolderObject->title = $postValues['title'];
384
				$documentFolderObject->slug = slugify($postValues['title']);
385
				$documentFolderObject->type = 'folder';
386
				$documentFolderObject->content = json_decode($postValues['content']);
0 ignored issues
show
Documentation introduced by
The property $content is declared protected in library\storage\Document. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
387
388
				return $documentFolderObject;
389
			} else {
390
				throw new \Exception('Trying to create document folder with invalid data.');
391
			}
392
		}
393
394
		/*
395
		 * 
396
		 * Sitemap
397
		 *
398
		 */
399
		/**
400
		 * @return array
401
		 */
402
		public function getSitemap()
403
		{
404
			return $this->repository->sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
405
		}
406
407
		/**
408
		 * Add a sitemap item
409
		 *
410
		 * @param $postValues
411
		 *
412
		 * @throws \Exception
413
		 */
414
		public function addSitemapItem($postValues) 
415
		{
416
			$sitemapObject = $this->createSitemapItemFromPostValues($postValues);
417
			$sitemap = $this->repository->sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
418
			$sitemap[] = $sitemapObject;
419
			$this->repository->sitemap = $sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
420
			$this->save();
421
		}
422
423
		/**
424
		 * Save changes to a sitemap item
425
		 *
426
		 * @param $slug
427
		 * @param $postValues
428
		 *
429
		 * @throws \Exception
430
		 */
431 View Code Duplication
		public function saveSitemapItem($slug, $postValues)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
432
		{
433
			$sitemapObject = $this->createSitemapItemFromPostValues($postValues);
434
			
435
			$sitemap = $this->repository->sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
436
			foreach ($sitemap as $key => $sitemapItem) {
437
				if ($sitemapItem->slug == $slug) {
438
					$sitemap[$key] = $sitemapObject;
439
				}
440
			}
441
			$this->repository->sitemap = $sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
442
			$this->save();
443
		}
444
445
		/**
446
		 * Delete a sitemap item by its slug
447
		 *
448
		 * @param $slug
449
		 *
450
		 * @throws \Exception
451
		 */
452 View Code Duplication
		public function deleteSitemapItemBySlug($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
453
		{
454
			$sitemap = $this->repository->sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
455
			foreach ($sitemap as $key => $sitemapItem) {
456
				if ($sitemapItem->slug == $slug) {
457
					unset($sitemap[$key]);
458
				}
459
			}
460
			$sitemap = array_values($sitemap);
461
			$this->repository->sitemap = $sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
462
			$this->save();
463
		}
464
465
		/**
466
		 * Create a sitemap item from post values
467
		 *
468
		 * @param $postValues
469
		 *
470
		 * @return \stdClass
471
		 * @throws \Exception
472
		 */
473
		private function createSitemapItemFromPostValues($postValues)
474
		{
475
			if (isset($postValues['title'], $postValues['url'], $postValues['component'], $postValues['template'])) {
476
				$sitemapObject = new \stdClass();
477
				$sitemapObject->title = $postValues['title'];
478
				$sitemapObject->slug = slugify($postValues['title']);
479
				$sitemapObject->url = $postValues['url'];
480
				$sitemapObject->component = $postValues['component'];
481
				$sitemapObject->template = $postValues['template'];
482
				$sitemapObject->regex = isset($postValues['regex']);
483
				$sitemapObject->parameters = new \stdClass();
484 View Code Duplication
				if (isset($postValues['parameterNames'], $postValues['parameterValues'])) {
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...
485
					foreach ($postValues['parameterNames'] as $key => $value) {
486
						$sitemapObject->parameters->$value = $postValues['parameterValues'][$key];
487
					}
488
				}
489
				return $sitemapObject;
490
			} else {
491
				throw new \Exception('Trying to create sitemap item with invalid data.');
492
			}
493
		}
494
495
		/**
496
		 * Save changes to a sitemap item
497
		 *
498
		 * @param $postValues
499
		 *
500
		 * @throws \Exception
501
		 */
502
		public function saveSitemap($postValues)
503
		{
504
			if (isset($postValues['sitemapitem']) && is_array($postValues['sitemapitem'])) {
505
				$sitemap = array();
506
				foreach ($postValues['sitemapitem'] as $sitemapItem) {
507
					$sitemapItemObject = json_decode($sitemapItem);
508
					if (isset($sitemapItemObject->object)) {
509
						unset($sitemapItemObject->object);
510
					}
511
					$sitemap[] = $sitemapItemObject;
512
				}
513
				$this->repository->sitemap = $sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
514
				$this->save();
515
			}
516
		}
517
518
		/**
519
		 * Get a sitemap item by its slug
520
		 *
521
		 * @param $slug
522
		 *
523
		 * @return mixed
524
		 */
525
		public function getSitemapItemBySlug($slug)
526
		{
527
			$sitemap = $this->repository->sitemap;
0 ignored issues
show
Documentation introduced by
The property $sitemap is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
528
			foreach ($sitemap as $sitemapItem) {
529
				if ($sitemapItem->slug == $slug) {
530
					return $sitemapItem;
531
				}
532
			}
533
			return null;
534
		}
535
536
		/*
537
		 *
538
		 * Images
539
		 *
540
		 */
541
		/**
542
		 * Get all images
543
		 *
544
		 * @return array
545
		 */
546
		public function getImages()
547
		{
548
			return $this->repository->images;
0 ignored issues
show
Documentation introduced by
The property $images is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
549
		}
550
551
		public function addImage($postValues)
552
		{
553
			$destinationPath = realpath(__DIR__ . '/../../www/images/');
554
555
			$filename = $this->validateFilename($postValues['name'], $destinationPath);
556
			$destination = $destinationPath . '/' . $filename;
557
558
			if ($postValues['error'] != '0') {
559
				throw new \Exception('Error uploading file. Error code: ' . $postValues['error']);
560
			}
561
562
			if (move_uploaded_file($postValues['tmp_name'], $destination)) {
563
				$imageResizer = new ImageResizer($this->getImageSet());
564
				$fileNames = $imageResizer->applyImageSetToImage($destination);
565
				$fileNames['original'] = $filename;
566
				$imageObject = new \stdClass();
567
				$imageObject->file = $filename;
568
				$imageObject->type = $postValues['type'];
569
				$imageObject->size = $postValues['size'];
570
				$imageObject->set = $fileNames;
571
572
                $images = $this->repository->images;
0 ignored issues
show
Documentation introduced by
The property $images is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
573
				$images[] = $imageObject;
574
                $this->repository->images = $images;
0 ignored issues
show
Documentation introduced by
The property $images is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
575
576
				$this->save();
577
			} else {
578
				throw new \Exception('Error moving uploaded file');
579
			}
580
		}
581
582 View Code Duplication
		public function deleteImageByName($filename)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
583
		{
584
			$destinationPath = realpath(__DIR__ . '/../../www/images/');
585
586
			$images = $this->getImages();
587
588
			foreach ($images as $key => $image) {
589
				if ($image->file == $filename) {
590
					foreach ($image->set as $imageSetFilename) {
591
						$destination = $destinationPath . '/' . $imageSetFilename;
592
						if (file_exists($destination)) {
593
							unlink($destination);
594
						} else {
595
							dump($destination);
596
						}
597
					}
598
					unset($images[$key]);
599
				}
600
			}
601
602
			$this->repository->images = $images;
0 ignored issues
show
Documentation introduced by
The property $images is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
603
			$this->save();
604
		}
605
606
		/**
607
		 * @param $filename
608
		 * @return null
609
         */
610
		public function getImageByName($filename)
611
		{
612
			$images = $this->getImages();
613
			foreach ($images as $image) {
614
				if ($image->file == $filename) {
615
					return $image;
616
				}
617
			}
618
			return null;
619
		}
620
621
		/*
622
		 *
623
		 * Files
624
		 *
625
		 */
626
		/**
627
		 * Get all files
628
		 *
629
		 * @return array
630
		 */
631
		public function getFiles()
632
		{
633
			$files =  $this->repository->files;
0 ignored issues
show
Documentation introduced by
The property $files is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
634
			usort($files, array($this, 'compareFiles'));
635
			return $files;
636
		}
637
638
		private function compareFiles($a, $b)
639
		{
640
			return strcmp($a->file, $b->file);
641
		}
642
643
		public function addFile($postValues)
644
		{
645
			$destinationPath = realpath(__DIR__ . '/../../www/files/');
646
647
			$filename = $this->validateFilename($postValues['name'], $destinationPath);
648
			$destination = $destinationPath . '/' . $filename;
649
650
			if ($postValues['error'] != '0') {
651
				throw new \Exception('Error uploading file. Error code: ' . $postValues['error']);
652
			}
653
654
			if (move_uploaded_file($postValues['tmp_name'], $destination)) {
655
				$file = new \stdClass();
656
				$file->file = $filename;
657
				$file->type = $postValues['type'];
658
				$file->size = $postValues['size'];
659
660
                $files = $this->repository->files;
0 ignored issues
show
Documentation introduced by
The property $files is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
661
				$files[] = $file;
662
                $this->repository->files = $files;
0 ignored issues
show
Documentation introduced by
The property $files is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
663
				$this->save();
664
			} else {
665
				throw new \Exception('Error moving uploaded file');
666
			}
667
		}
668
669
		private function validateFilename($filename, $path)
670
		{
671
			$fileParts = explode('.', $filename);
672 View Code Duplication
			if (count($fileParts) > 1) {
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...
673
				$extension = end($fileParts);
674
				array_pop($fileParts);
675
				$fileNameWithoutExtension = implode('-', $fileParts);
676
				$fileNameWithoutExtension = slugify($fileNameWithoutExtension);
677
				$filename = $fileNameWithoutExtension . '.' . $extension;
678
			} else {
679
				$filename = slugify($filename);
680
			}
681
682 View Code Duplication
			if (file_exists($path . '/' . $filename)) {
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...
683
				$fileParts = explode('.', $filename);
684
				if (count($fileParts) > 1) {
685
					$extension = end($fileParts);
686
					array_pop($fileParts);
687
					$fileNameWithoutExtension = implode('-', $fileParts);
688
					$fileNameWithoutExtension .= '-copy';
689
					$filename = $fileNameWithoutExtension . '.' . $extension;
690
				} else {
691
					$filename .= '-copy';
692
				}
693
				return $this->validateFilename($filename,$path);
694
			}
695
			return $filename;
696
		}
697
698
		/**
699
		 * @param $filename
700
		 * @return null
701
         */
702
		public function getFileByName($filename)
703
		{
704
			$files = $this->getFiles();
705
			foreach ($files as $file) {
706
				if ($filename == $file->file) {
707
					return $file;
708
				}
709
			}
710
			return null;
711
		}
712
713
		/**
714
		 * @param $filename
715
		 * @throws \Exception
716
         */
717 View Code Duplication
		public function deleteFileByName($filename)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
718
		{
719
			$destinationPath = realpath(__DIR__ . '/../../www/files/');
720
			$destination = $destinationPath . '/' . $filename;
721
722
			if (file_exists($destination)) {
723
				$files = $this->getFiles();
724
				foreach ($files as $key => $file) {
725
					if ($file->file == $filename) {
726
						unlink($destination);
727
						unset($files[$key]);
728
					}
729
				}
730
731
				$files = array_values($files);
732
				$this->repository->files = $files;
0 ignored issues
show
Documentation introduced by
The property $files is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
733
				$this->save();
734
			}
735
		}
736
737
		/*
738
		 * 
739
		 * Configuration
740
		 *
741
		 */
742
		/**
743
		 * @return array
744
		 */
745
		public function getDocumentTypes()
746
		{
747
			return $this->repository->documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
748
		}
749
750
		/**
751
		 * Add a document type from post values
752
		 *
753
		 * @param $postValues
754
		 *
755
		 * @throws \Exception
756
		 */
757
		public function addDocumentType($postValues)
758
		{
759
			$documentTypeObject = $this->createDocumentTypeFromPostValues($postValues);
760
761
            $documentTypes = $this->repository->documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
762
            $documentTypes[] = $documentTypeObject;
763
            $this->repository->documentTypes = $documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
764
765
			$this->save();
766
		}
767
768
		/**
769
		 * Create a document type from post values
770
		 *
771
		 * @param $postValues
772
		 *
773
		 * @return \stdClass
774
		 * @throws \Exception
775
		 */
776
		public function createDocumentTypeFromPostValues($postValues)
777
		{
778
			if (isset($postValues['title'])) {
779
				$documentTypeObject = new \stdClass();
780
				$documentTypeObject->title = $postValues['title'];
781
				$documentTypeObject->slug = slugify($postValues['title']);
782
				$documentTypeObject->fields = array();
783
				$documentTypeObject->bricks = array();
784
				$documentTypeObject->dynamicBricks = isset($postValues['dynamicBricks']) ? $postValues['dynamicBricks'] : array();
785 View Code Duplication
				if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) {
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...
786
					foreach ($postValues['fieldTitles'] as $key => $value) {
787
						$fieldObject = new \stdClass();
788
						$fieldObject->title = $value;
789
						$fieldObject->slug = slugify($value);
790
						$fieldObject->type = $postValues['fieldTypes'][$key];
791
						$fieldObject->required = ($postValues['fieldRequired'][$key] === 'true');
792
						$fieldObject->multiple = ($postValues['fieldMultiple'][$key] === 'true');
793
						
794
						$documentTypeObject->fields[] = $fieldObject;
795
					}
796
				}
797
				if (isset($postValues['brickTitles'], $postValues['brickBricks'])) {
798
					foreach ($postValues['brickTitles'] as $key => $value) {
799
						$brickObject = new \stdClass();
800
						$brickObject->title = $value;
801
						$brickObject->slug = slugify($value);
802
						$brickObject->brickSlug = $postValues['brickBricks'][$key];
803
						$brickObject->multiple = ($postValues['brickMultiples'][$key] === 'true');
804
805
						$documentTypeObject->bricks[] = $brickObject;
806
					}
807
				}
808
				return $documentTypeObject;
809
			} else {
810
				throw new \Exception('Trying to create document type with invalid data.');
811
			}
812
		}
813
814
		/**
815
		 * Delete document type
816
		 *
817
		 * @param $slug
818
		 *
819
		 * @throws \Exception
820
		 */
821 View Code Duplication
		public function deleteDocumentTypeBySlug($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
822
		{
823
			$documentTypes = $this->repository->documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
824
			foreach ($documentTypes as $key => $documentTypeObject) {
825
				if ($documentTypeObject->slug == $slug) {
826
					unset($documentTypes[$key]);
827
				}
828
			}
829
			$documentTypes = array_values($documentTypes);
830
			$this->repository->documentTypes = $documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
831
			$this->save();
832
		}
833
834
		/**
835
		 * Get document type by its slug
836
		 *
837
		 * @param      $slug
838
		 * @param bool $getBricks
839
		 *
840
		 * @return mixed
841
		 */
842
		public function getDocumentTypeBySlug($slug, $getBricks = false)
843
		{
844
			$documentTypes = $this->repository->documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
845
			foreach ($documentTypes as $documentType) {
846
				if ($documentType->slug == $slug) {
847
					if ($getBricks === true) {
848
						foreach ($documentType->bricks as $key => $brick) {
849
							$brickStructure = $this->getBrickBySlug($brick->brickSlug);
850
							$documentType->bricks[$key]->structure = $brickStructure;
851
						}
852
						foreach ($documentType->dynamicBricks as $key => $brickSlug) {
853
							$brickStructure = $this->getBrickBySlug($brickSlug);
854
							$documentType->dynamicBricks[$key] = $brickStructure;
855
						}
856
					}
857
					return $documentType;
858
				}
859
			}
860
			return null;
861
		}
862
863
		/**
864
		 * Save changes to a document type
865
		 *
866
		 * @param $slug
867
		 * @param $postValues
868
		 *
869
		 * @throws \Exception
870
		 */
871 View Code Duplication
		public function saveDocumentType($slug, $postValues)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
872
		{
873
			$documentTypeObject = $this->createDocumentTypeFromPostValues($postValues);
874
			
875
			$documentTypes = $this->repository->documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
876
			foreach ($documentTypes as $key => $documentType) {
877
				if ($documentType->slug == $slug) {
878
					$documentTypes[$key] = $documentTypeObject;
879
				}
880
			}
881
			$this->repository->documentTypes = $documentTypes;
0 ignored issues
show
Documentation introduced by
The property $documentTypes is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
882
			$this->save();
883
		}
884
		
885
		/*
886
		 *
887
		 * Bricks
888
		 *
889
		 */
890
		/**
891
		 * @return array
892
		 */
893
		public function getBricks()
894
		{
895
			return $this->repository->bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
896
		}
897
898
		/**
899
		 * Add a brick
900
		 *
901
		 * @param $postValues
902
		 *
903
		 * @throws \Exception
904
		 */
905
		public function addBrick($postValues)
906
		{
907
			$brickObject = $this->createBrickFromPostValues($postValues);
908
909
            $bricks = $this->repository->bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
910
            $bricks[] = $brickObject;
911
            $this->repository->bricks = $bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
912
913
			$this->save();
914
		}
915
916
		/**
917
		 * Create a brick from post values
918
		 *
919
		 * @param $postValues
920
		 *
921
		 * @return \stdClass
922
		 * @throws \Exception
923
		 */
924
		public function createBrickFromPostValues($postValues)
925
		{
926
			if (isset($postValues['title'])) {
927
				$brickObject = new \stdClass();
928
				$brickObject->title = $postValues['title'];
929
				$brickObject->slug = slugify($postValues['title']);
930
				$brickObject->fields = array();
931 View Code Duplication
				if (isset($postValues['fieldTitles'], $postValues['fieldTypes'], $postValues['fieldRequired'], $postValues['fieldMultiple'])) {
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...
932
					foreach ($postValues['fieldTitles'] as $key => $value) {
933
						$fieldObject = new \stdClass();
934
						$fieldObject->title = $value;
935
						$fieldObject->slug = slugify($value);
936
						$fieldObject->type = $postValues['fieldTypes'][$key];
937
						$fieldObject->required = ($postValues['fieldRequired'][$key] === 'true');
938
						$fieldObject->multiple = ($postValues['fieldMultiple'][$key] === 'true');
939
						
940
						$brickObject->fields[] = $fieldObject;
941
					}
942
				}
943
				return $brickObject;
944
			} else {
945
				throw new \Exception('Trying to create document type with invalid data.');
946
			}
947
		}
948
949
		/**
950
		 * Get a brick by its slug
951
		 *
952
		 * @param $slug
953
		 *
954
		 * @return \stdClass
955
		 */
956
		public function getBrickBySlug($slug)
957
		{
958
			$bricks = $this->repository->bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
959
			foreach ($bricks as $brick) {
960
				if ($brick->slug == $slug) {
961
					return $brick;
962
				}
963
			}
964
			return null;
965
		}
966
967
		/**
968
		 * Save changes to a brick
969
		 *
970
		 * @param $slug
971
		 * @param $postValues
972
		 *
973
		 * @throws \Exception
974
		 */
975 View Code Duplication
		public function saveBrick($slug, $postValues)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
976
		{
977
			$brickObject = $this->createBrickFromPostValues($postValues);
978
			
979
			$bricks = $this->repository->bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
980
			foreach ($bricks as $key => $brick) {
981
				if ($brick->slug == $slug) {
982
					$bricks[$key] = $brickObject;
983
				}
984
			}
985
			$this->repository->bricks = $bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
986
			$this->save();
987
		}
988
989
		/**
990
		 * Delete a brick by its slug
991
		 *
992
		 * @param $slug
993
		 *
994
		 * @throws \Exception
995
		 */
996 View Code Duplication
		public function deleteBrickBySlug($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
997
		{
998
			$bricks = $this->repository->bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
999
			foreach ($bricks as $key => $brickObject) {
1000
				if ($brickObject->slug == $slug) {
1001
					unset($bricks[$key]);
1002
				}
1003
			}
1004
			
1005
			$bricks = array_values($bricks);
1006
			$this->repository->bricks = $bricks;
0 ignored issues
show
Documentation introduced by
The property $bricks is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1007
			$this->save();
1008
		}
1009
		
1010
		/*
1011
		 * 
1012
		 * Misc
1013
		 *
1014
		 */
1015
		/**
1016
		 * Save changes made to the repository
1017
		 *
1018
		 * @throws \Exception
1019
		 */
1020
		private function save() {
1021
			$this->repository->save();
1022
		}
1023
1024
		/*
1025
		 *
1026
		 * Image Set
1027
		 *
1028
		 */
1029
1030
		/**
1031
		 * Get the image set
1032
		 *
1033
		 * @return array
1034
		 */
1035
		public function getImageSet()
1036
		{
1037
			return $this->repository->imageSet;
0 ignored issues
show
Documentation introduced by
The property $imageSet is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
1038
		}
1039
1040
		/**
1041
		 * Get Image by slug
1042
		 *
1043
		 * @param $slug
1044
		 *
1045
		 * @return \stdClass
1046
		 */
1047
		public function getImageSetBySlug($slug)
1048
		{
1049
			$imageSet = $this->getImageSet();
1050
			foreach ($imageSet as $set) {
1051
				if ($set->slug == $slug) {
1052
					return $set;
1053
				}
1054
			}
1055
			return null;
1056
		}
1057
1058
		/**
1059
		 * Save Image Set by it's slug
1060
		 *
1061
		 * @param $slug
1062
		 * @param $postValues
1063
		 *
1064
		 * @throws \Exception
1065
		 */
1066
		public function saveImageSet($slug, $postValues)
1067
		{
1068
			$imageSetObject = $this->createImageSetFromPostValues($postValues);
1069
1070
			$imageSet = $this->repository->imageSet;
0 ignored issues
show
Documentation introduced by
The property $imageSet is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
1071
			foreach ($imageSet as $key => $set) {
1072
				if ($set->slug == $slug) {
1073
					$imageSet[$key] = $imageSetObject;
1074
				}
1075
			}
1076
			$this->repository->imageSet = $imageSet;
0 ignored issues
show
Documentation introduced by
The property $imageSet is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1077
			$this->save();
1078
		}
1079
1080
		/**
1081
		 * Ceate image set from post values
1082
		 *
1083
		 * @param $postValues
1084
		 *
1085
		 * @return \stdClass
1086
		 * @throws \Exception
1087
		 */
1088
		private function createImageSetFromPostValues($postValues)
1089
		{
1090
			if (isset($postValues['title'], $postValues['width'], $postValues['height'], $postValues['method'])) {
1091
				$imageSetObject = new \stdClass();
1092
1093
				$imageSetObject->title = $postValues['title'];
1094
				$imageSetObject->slug = slugify($postValues['title']);
1095
				$imageSetObject->width = $postValues['width'];
1096
				$imageSetObject->height = $postValues['height'];
1097
				$imageSetObject->method = $postValues['method'];
1098
1099
				return $imageSetObject;
1100
			} else {
1101
				throw new \Exception('Trying to create image set with invalid data.');
1102
			}
1103
		}
1104
1105
		/**
1106
		 * Add image set
1107
		 *
1108
		 * @param $postValues
1109
		 *
1110
		 * @throws \Exception
1111
		 */
1112
		public function addImageSet($postValues)
1113
		{
1114
			$imageSetObject = $this->createImageSetFromPostValues($postValues);
1115
1116
            $imageSet = $this->repository->imageSet;
0 ignored issues
show
Documentation introduced by
The property $imageSet is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
1117
            $imageSet[] = $imageSetObject;
1118
            $this->repository->imageSet = $imageSet;
0 ignored issues
show
Documentation introduced by
The property $imageSet is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1119
1120
			$this->save();
1121
		}
1122
1123
		/**
1124
		 * Delete Image Set by its slug
1125
		 *
1126
		 * @param $slug
1127
		 *
1128
		 * @throws \Exception
1129
		 */
1130
		public function deleteImageSetBySlug($slug)
1131
		{
1132
			$imageSet = $this->getImageSet();
1133
1134
			foreach ($imageSet as $key => $set) {
1135
				if ($set->slug == $slug) {
1136
					unset($imageSet[$key]);
1137
				}
1138
			}
1139
			$imageSet = array_values($imageSet);
1140
			$this->repository->imageSet = $imageSet;
0 ignored issues
show
Documentation introduced by
The property $imageSet is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1141
			$this->save();
1142
		}
1143
1144
		/**
1145
		 * Get the image set with the smallest size
1146
		 *
1147
		 * @return \stdClass
1148
		 */
1149
		public function getSmallestImageSet()
1150
		{
1151
			$imageSet = $this->getImageSet();
1152
1153
			$returnSize = PHP_INT_MAX;
1154
			$returnSet = null;
1155
1156
			foreach ($imageSet as $set) {
1157
				$size = $set->width * $set->height;
1158
				if ($size < $returnSize) {
1159
					$returnSize = $size;
1160
					$returnSet = $set;
1161
				}
1162
			}
1163
1164
			if ($returnSet === null) {
1165
				$returnSet = new \stdClass();
1166
				$returnSet->slug = 'original';
1167
			}
1168
1169
			return $returnSet;
1170
		}
1171
1172
		/**
1173
		 * @return array
1174
		 */
1175
		public function getApplicationComponents()
1176
		{
1177
			return $this->repository->applicationComponents;
0 ignored issues
show
Documentation introduced by
The property $applicationComponents is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
1178
		}
1179
1180
		public function addApplicationComponent($postValues)
1181
		{
1182
			$applicationComponent = $this->createApplicationComponentFromPostValues($postValues);
1183
			$applicationComponents = $this->repository->applicationComponents;
0 ignored issues
show
Documentation introduced by
The property $applicationComponents is declared protected in library\storage\Repository. Since you implemented __get(), maybe consider adding a @property or @property-read annotation. This makes it easier for IDEs to provide auto-completion.

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...
1184
			$applicationComponents[] = $applicationComponent;
1185
			$this->repository->applicationComponents = $applicationComponents;
0 ignored issues
show
Documentation introduced by
The property $applicationComponents is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1186
1187
			$this->save();
1188
		}
1189
1190
		private function createApplicationComponentFromPostValues($postValues)
1191
		{
1192
			if (isset($postValues['title'], $postValues['component'])) {
1193
				$applicationComponent = new \stdClass();
1194
				$applicationComponent->title = $postValues['title'];
1195
				$applicationComponent->slug = slugify($postValues['title']);
1196
				$applicationComponent->component = $postValues['component'];
1197
				$applicationComponent->parameters = new \stdClass();
1198 View Code Duplication
				if (isset($postValues['parameterNames'], $postValues['parameterValues'])) {
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...
1199
					foreach ($postValues['parameterNames'] as $key => $value) {
1200
						$applicationComponent->parameters->$value = $postValues['parameterValues'][$key];
1201
					}
1202
				}
1203
				return $applicationComponent;
1204
			} else {
1205
				throw new \Exception('Trying to create application component with invalid data.');
1206
			}
1207
		}
1208
1209
		public function getApplicationComponentBySlug($slug)
1210
		{
1211
			$applicationComponents = $this->getApplicationComponents();
1212
			foreach ($applicationComponents as $applicationComponent) {
1213
				if ($applicationComponent->slug == $slug) {
1214
					return $applicationComponent;
1215
				}
1216
			}
1217
			return null;
1218
		}
1219
1220 View Code Duplication
		public function saveApplicationComponent($slug, $postValues)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1221
		{
1222
			$newApplicationComponent = $this->createApplicationComponentFromPostValues($postValues);
1223
1224
			$applicationComponents = $this->getApplicationComponents();
1225
			foreach ($applicationComponents as $key => $applicationComponent) {
1226
				if ($applicationComponent->slug == $slug) {
1227
					$applicationComponents[$key] = $newApplicationComponent;
1228
				}
1229
			}
1230
			$this->repository->applicationComponents = $applicationComponents;
0 ignored issues
show
Documentation introduced by
The property $applicationComponents is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1231
			$this->save();
1232
		}
1233
1234 View Code Duplication
		public function deleteApplicationComponentBySlug($slug)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
1235
		{
1236
			$applicationComponents = $this->getApplicationComponents();
1237
			foreach ($applicationComponents as $key => $applicationComponent) {
1238
				if ($applicationComponent->slug == $slug) {
1239
					unset($applicationComponents[$key]);
1240
				}
1241
			}
1242
			$applicationComponents = array_values($applicationComponents);
1243
			$this->repository->applicationComponents = $applicationComponents;
0 ignored issues
show
Documentation introduced by
The property $applicationComponents is declared protected in library\storage\Repository. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

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...
1244
			$this->save();
1245
		}
1246
1247
		private function getEncodedRepository()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
1248
		{
1249
			$json = json_encode($this->repository);
1250
			if ($json === false) {
1251
				$this->throwJsonException();
1252
			}
1253
			return $json;
1254
		}
1255
1256
		private function throwJsonException()
1257
		{
1258
			$error = 'JSON Encoding failed';
1259
			switch (json_last_error()) {
1260
				case JSON_ERROR_NONE:
1261
					$error .= ' - No errors';
1262
					break;
1263
				case JSON_ERROR_DEPTH:
1264
					$error .= ' - Maximum stack depth exceeded';
1265
					break;
1266
				case JSON_ERROR_STATE_MISMATCH:
1267
					$error .= ' - Underflow or the modes mismatch';
1268
					break;
1269
				case JSON_ERROR_CTRL_CHAR:
1270
					$error .= ' - Unexpected control character found';
1271
					break;
1272
				case JSON_ERROR_SYNTAX:
1273
					$error .= ' - Syntax error, malformed JSON';
1274
					break;
1275
				case JSON_ERROR_UTF8:
1276
					$error .= ' - Malformed UTF-8 characters, possibly incorrectly encoded';
1277
					break;
1278
				default:
1279
					$error .= ' - Unknown error';
1280
					break;
1281
			}
1282
1283
			throw new \Exception($error);
1284
		}
1285
	}
1286
}