MutatorContext   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 14
c 2
b 0
f 0
dl 0
loc 39
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getAttributeRelativeName() 0 3 1
A assert() 0 4 2
A getAttributeAbsoluteName() 0 3 2
A from() 0 3 1
A raise() 0 4 1
1
<?php
2
3
namespace Ipag\Sdk\Model\Schema;
4
5
use Ipag\Sdk\Model\Schema\Exception\MutatorAttributeException;
6
use Ipag\Sdk\Model\Schema\SchemaAttribute;
7
use Ipag\Sdk\Model\Model;
8
9
/**
10
 * @codeCoverageIgnore
11
 */
12
final class MutatorContext
13
{
14
    public Model $target;
15
    public string $attribute;
16
    public ?SchemaAttribute $attributeSchema;
17
18
    public function __construct(Model $target, string $attribute, ?SchemaAttribute $attributeSchema = null)
19
    {
20
        $this->target = $target;
21
        $this->attribute = $attribute;
22
        $this->attributeSchema = $attributeSchema;
23
    }
24
25
    public function raise(?string $message = null): void
26
    {
27
        $attributeAbsoluteName = $this->getAttributeAbsoluteName();
28
        throw new MutatorAttributeException($attributeAbsoluteName, $message);
29
    }
30
31
    public function assert($conditional, ?string $message = null): void
32
    {
33
        if (!$conditional) {
34
            $this->raise($message);
35
        }
36
    }
37
38
    public function getAttributeRelativeName(): string
39
    {
40
        return implode('.', [$this->target->getName(), $this->attribute]);
0 ignored issues
show
Bug introduced by
The method getName() does not exist on Ipag\Sdk\Model\Model. It seems like you code against a sub-type of Ipag\Sdk\Model\Model such as Ipag\Sdk\Model\Product or Ipag\Sdk\Model\AntifraudProvider or Ipag\Sdk\Model\Seller or Ipag\Sdk\Model\SubscriptionPlan or Ipag\Sdk\Support\Provide...audes\ClearSaleProvider or Ipag\Sdk\Support\Provide...fraudes\KondutoProvider or Ipag\Sdk\Model\Event or Ipag\Sdk\Model\Owner or Ipag\Sdk\Support\Provide...audes\RedShieldProvider or Ipag\Sdk\Model\Holder or Ipag\Sdk\Support\Credent...es\ClearSaleCredentials or Ipag\Sdk\Model\Venue or Ipag\Sdk\Model\Customer or Ipag\Sdk\Model\Establishment. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

40
        return implode('.', [$this->target->/** @scrutinizer ignore-call */ getName(), $this->attribute]);
Loading history...
41
    }
42
43
    public function getAttributeAbsoluteName(): string
44
    {
45
        return $this->attributeSchema ? $this->attributeSchema->getAbsoluteName() : $this->getAttributeRelativeName();
46
    }
47
48
    public static function from(Model $target, string $attribute, ?SchemaAttribute $attributeSchema = null): self
49
    {
50
        return new self($target, $attribute, $attributeSchema);
51
    }
52
}