Completed
Push — 4.0 ( af9dea...2073b3 )
by Olivier
03:18 queued 55s
created

UserLacksOwnership   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 15.22 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 0
cbo 1
dl 7
loc 46
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_user() 0 4 1
A get_resource() 0 4 1
A __construct() 7 7 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
/*
4
 * This file is part of the Icybee package.
5
 *
6
 * (c) Olivier Laviale <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Icybee\Modules\Users;
13
14
use ICanBoogie\Accessor\AccessorTrait;
15
use ICanBoogie\HTTP\Status;
16
17
/**
18
 * Exception thrown when the user lacks ownership of a resource.
19
 *
20
 * @property-read User $user
21
 * @property-read mixed $resource
22
 */
23
class UserLacksOwnership extends \Exception
24
{
25
	use AccessorTrait;
26
27
	const DEFAULT_MESSAGE = 'User lacks ownership of the resource.';
28
29
	/**
30
	 * @var User
31
	 */
32
	private $user;
33
34
	/**
35
	 * @return User
36
	 */
37
	protected function get_user()
38
	{
39
		return $this->user;
40
	}
41
42
	/**
43
	 * @var mixed
44
	 */
45
	private $resource;
46
47
	/**
48
	 * @return mixed
49
	 */
50
	protected function get_resource()
51
	{
52
		return $this->resource;
53
	}
54
55
	/**
56
	 * @param User $user
57
	 * @param mixed $resource
58
	 * @param string $message
59
	 * @param \Exception|null $previous
60
	 */
61 View Code Duplication
	public function __construct(User $user, $resource, $message = self::DEFAULT_MESSAGE, \Exception $previous = null)
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...
62
	{
63
		$this->user = $user;
64
		$this->resource = $resource;
65
66
		parent::__construct($message, Status::FORBIDDEN, $previous);
67
	}
68
}
69