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); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
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:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: