MetadataAttributeOverrideException::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 7
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 7
cts 7
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 3
crap 2
1
<?php
2
declare(strict_types = 1);
3
4
namespace Mikemirten\Component\JsonApi\Document\Exception;
5
6
use Mikemirten\Component\JsonApi\Document\Behaviour\MetadataAwareInterface;
7
8
/**
9
 * Class MetadataAttributeOverrideException
10
 *
11
 * @package Mikemirten\Component\JsonApi\Document\Exception
12
 */
13 View Code Duplication
class MetadataAttributeOverrideException 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
     * MetadataAttributeOverrideException constructor.
17
     *
18
     * @param MetadataAwareInterface $container
19
     * @param string                 $name
20
     * @param \Exception | null      $previous
21
     */
22 13
    public function __construct(MetadataAwareInterface $container, string $name, \Exception $previous = null)
23
    {
24 13
        $info = method_exists($container, '__toString')
25 13
            ? (string) $container
26 13
            : get_class($container);
27
28 13
        $message = sprintf('Attribute "%s" of metadata already exists inside of [%s]. To set new one, the old one must be removed.', $name, $info);
29
30 13
        parent::__construct($message, 0, $previous);
31
    }
32
}