|
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\Reflection\Base\Dependent\BaseArgument; |
|
13
|
|
|
use Railt\Reflection\Contracts\Definitions\TypeDefinition; |
|
14
|
|
|
use Railt\Reflection\Contracts\Dependent\FieldDefinition; |
|
15
|
|
|
use Railt\SDL\Schema\CompilerInterface; |
|
16
|
|
|
use Railt\SDL\Schema\Configuration; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class DiffArgument |
|
20
|
|
|
*/ |
|
21
|
|
|
class DiffArgument extends BaseArgument |
|
22
|
|
|
{ |
|
23
|
|
|
public const ARGUMENT_NAME = 'diff'; |
|
24
|
|
|
public const ARGUMENT_DESCRIPTION = ' |
|
25
|
|
|
An argument that matches the date of the time difference. |
|
26
|
|
|
|
|
27
|
|
|
If a `NULL` is passed (or the value is not passed), |
|
28
|
|
|
then the current time is taken. |
|
29
|
|
|
'; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* @var CompilerInterface|Configuration |
|
33
|
|
|
*/ |
|
34
|
|
|
private $compiler; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* DiffArgument constructor. |
|
38
|
|
|
* @param FieldDefinition $field |
|
39
|
|
|
* @param CompilerInterface $compiler |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(FieldDefinition $field, CompilerInterface $compiler) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->compiler = $compiler; |
|
44
|
|
|
$this->name = self::ARGUMENT_NAME; |
|
45
|
|
|
$this->description = self::ARGUMENT_DESCRIPTION; |
|
46
|
|
|
|
|
47
|
|
|
$this->parent = $field; |
|
48
|
|
|
|
|
49
|
|
|
$this->defaultValue = null; |
|
50
|
|
|
$this->hasDefaultValue = true; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* @return TypeDefinition |
|
55
|
|
|
*/ |
|
56
|
|
|
public function getTypeDefinition(): TypeDefinition |
|
57
|
|
|
{ |
|
58
|
|
|
return $this->compiler->getDictionary()->get('Carbon', $this); |
|
|
|
|
|
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|
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: