Completed
Push — master ( c762b0...684d44 )
by John
02:56
created

ScalarSchema::isDateTime()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 3
nc 3
nop 0
1
<?php declare(strict_types = 1);
2
/*
3
 * This file is part of the KleijnWeb\ApiDescriptions 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
namespace KleijnWeb\ApiDescriptions\Description\Schema;
9
10
/**
11
 * Represents standard JSON Schema but with support for complex types
12
 *
13
 * @author John Kleijn <[email protected]>
14
 */
15
class ScalarSchema extends Schema
16
{
17
    /**
18
     * @var string
19
     */
20
    protected $type;
21
22
    /**
23
     * @var string|null
24
     */
25
    protected $format;
26
27
    /**
28
     * ScalarSchema constructor.
29
     */
30
    public function __construct(\stdClass $definition)
31
    {
32
        parent::__construct($definition);
33
        $this->format = isset($definition->format) ? $definition->format : null;
34
    }
35
36
    /**
37
     * @return bool
38
     */
39
    public function isDateTime(): bool
40
    {
41
        return $this->isType(self::TYPE_STRING)
42
        && ($this->hasFormat(self::FORMAT_DATE) || $this->hasFormat(self::FORMAT_DATE_TIME));
43
    }
44
45
    /**
46
     * @return string
47
     */
48
    public function getFormat()
49
    {
50
        return $this->format;
51
    }
52
53
    /**
54
     * @param string $format
55
     *
56
     * @return bool
57
     */
58
    public function hasFormat(string $format): bool
59
    {
60
        return $this->format === $format;
61
    }
62
}
63