RelationshipNotFoundException   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 57
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 57
loc 57
ccs 13
cts 13
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 13 13 2
A getName() 4 4 1
A getContainer() 4 4 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
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document\Exception;
5
6
use Mikemirten\Component\JsonApi\Document\Behaviour\RelationshipsAwareInterface;
7
8
/**
9
 * Class RelationshipNotFoundException
10
 *
11
 * @package Mikemirten\Component\JsonApi\Exception
12
 */
13 View Code Duplication
class RelationshipNotFoundException extends DocumentException
0 ignored issues
show
Duplication introduced by
This class 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...
14
{
15
    /**
16
     * Name of not found relationship
17
     *
18
     * @var string
19
     */
20
    protected $name;
21
22
    /**
23
     * Container inside of which a relationship has not been found
24
     *
25
     * @var RelationshipsAwareInterface
26
     */
27
    protected $container;
28
29
    /**
30
     * RelationshipNotFoundException constructor.
31
     *
32
     * @param RelationshipsAwareInterface $container
33
     * @param string                      $name
34
     * @param \Exception | null           $previous
35
     */
36 2
    public function __construct(RelationshipsAwareInterface $container, string $name, \Exception $previous = null)
37
    {
38 2
        $this->name      = $name;
39 2
        $this->container = $container;
40
41 2
        $info = method_exists($container, '__toString')
42 1
            ? (string) $container
43 2
            : get_class($container);
44
45 2
        $message = sprintf('Relationship "%s" not found inside of [%s].', $name, $info);
46
47 2
        parent::__construct($message, 0, $previous);
48 2
    }
49
50
    /**
51
     * Get name of not found relationship
52
     *
53
     * @return string
54
     */
55 1
    public function getName(): string
56
    {
57 1
        return $this->name;
58
    }
59
60
    /**
61
     * Get container inside of which a relationship has not been found
62
     *
63
     * @return RelationshipsAwareInterface
64
     */
65 1
    public function getContainer(): RelationshipsAwareInterface
66
    {
67 1
        return $this->container;
68
    }
69
}