FormatArgument   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A getTypeDefinition() 0 4 1
1
<?php
2
/**
3
 * This file is part of Railt package.
4
 *
5
 * For the full copyright and license information, please view the LICENSE
6
 * file that was distributed with this source code.
7
 */
8
declare(strict_types=1);
9
10
namespace Railt\CarbonExtension\TypeDefinition;
11
12
use Railt\CarbonExtension\In\CarbonFormat;
13
use Railt\SDL\Base\Dependent\BaseArgument;
14
use Railt\SDL\Contracts\Definitions\TypeDefinition;
15
use Railt\SDL\Contracts\Dependent\FieldDefinition;
16
use Railt\SDL\Schema\CompilerInterface;
17
use Railt\SDL\Schema\Configuration;
18
19
/**
20
 * Class FormatArgument
21
 */
22
class FormatArgument extends BaseArgument
23
{
24
    public const ARGUMENT_NAME        = 'format';
25
    public const ARGUMENT_DESCRIPTION = '
26
        An argument that provides a format of the given value that 
27
        are contained in a CarbonFormat enumeration type
28
    ';
29
30
    /**
31
     * @var CompilerInterface|Configuration
32
     */
33
    private $compiler;
34
35
    /**
36
     * DiffArgument constructor.
37
     * @param FieldDefinition $field
38
     * @param CompilerInterface $compiler
39
     */
40
    public function __construct(FieldDefinition $field, CompilerInterface $compiler)
41
    {
42
        $this->compiler    = $compiler;
43
        $this->name        = self::ARGUMENT_NAME;
44
        $this->description = self::ARGUMENT_DESCRIPTION;
45
46
        $this->parent = $field;
47
48
        $this->defaultValue    = CarbonFormat::DEFAULT;
49
        $this->hasDefaultValue = true;
50
    }
51
52
    /**
53
     * @return TypeDefinition
54
     */
55
    public function getTypeDefinition(): TypeDefinition
56
    {
57
        return $this->compiler->getDictionary()->get('CarbonFormat', $this);
0 ignored issues
show
Bug introduced by
The method getDictionary does only exist in Railt\SDL\Schema\Configuration, but not in Railt\SDL\Schema\CompilerInterface.

It seems like the method you are trying to call exists only in some of the possible types.

Let’s take a look at an example:

class A
{
    public function foo() { }
}

class B extends A
{
    public function bar() { }
}

/**
 * @param A|B $x
 */
function someFunction($x)
{
    $x->foo(); // This call is fine as the method exists in A and B.
    $x->bar(); // This method only exists in B and might cause an error.
}

Available Fixes

  1. Add an additional type-check:

    /**
     * @param A|B $x
     */
    function someFunction($x)
    {
        $x->foo();
    
        if ($x instanceof B) {
            $x->bar();
        }
    }
    
  2. Only allow a single type to be passed if the variable comes from a parameter:

    function someFunction(B $x) { /** ... */ }
    
Loading history...
58
    }
59
}
60