• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

api-platform / core / 10315659289

09 Aug 2024 07:49AM UTC coverage: 7.841% (-0.006%) from 7.847%
10315659289

push

github

soyuka
style: cs fixes

70 of 529 new or added lines in 176 files covered. (13.23%)

160 existing lines in 58 files now uncovered.

12688 of 161818 relevant lines covered (7.84%)

26.86 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/tests/Fixtures/TestBundle/GraphQl/Type/Definition/DateTimeType.php
1
<?php
2

3
/*
4
 * This file is part of the API Platform project.
5
 *
6
 * (c) Kévin Dunglas <dunglas@gmail.com>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types=1);
13

14
namespace ApiPlatform\Tests\Fixtures\TestBundle\GraphQl\Type\Definition;
15

16
use ApiPlatform\GraphQl\Type\Definition\TypeInterface;
17
use GraphQL\Error\Error;
18
use GraphQL\Language\AST\Node;
19
use GraphQL\Language\AST\StringValueNode;
20
use GraphQL\Type\Definition\ScalarType;
21
use GraphQL\Utils\Utils;
22

23
/**
24
 * Represents a DateTime type.
25
 *
26
 * @author Alan Poulain <contact@alanpoulain.eu>
27
 */
28
final class DateTimeType extends ScalarType implements TypeInterface
29
{
30
    public function __construct()
31
    {
32
        $this->name = \DateTime::class;
×
33
        $this->description = 'The `DateTime` scalar type represents time data.';
×
34

35
        parent::__construct();
×
36
    }
37

38
    public function getName(): string
39
    {
40
        return $this->name;
×
41
    }
42

43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function serialize($value): string
47
    {
48
        // Already serialized.
49
        if (\is_string($value)) {
×
50
            // Should be better in a custom normalizer.
51
            return (new \DateTime($value))->format('Y-m-d');
×
52
        }
53

54
        if (!($value instanceof \DateTime)) {
×
NEW
55
            throw new Error(\sprintf('Value must be an instance of DateTime to be represented by DateTime: %s', Utils::printSafe($value)));
×
56
        }
57

58
        return $value->format(\DateTime::ATOM);
×
59
    }
60

61
    /**
62
     * {@inheritdoc}
63
     */
64
    public function parseValue($value): string
65
    {
66
        if (!\is_string($value)) {
×
NEW
67
            throw new Error(\sprintf('DateTime cannot represent non string value: %s', Utils::printSafeJson($value)));
×
68
        }
69

70
        if (false === \DateTime::createFromFormat(\DateTime::ATOM, $value)) {
×
NEW
71
            throw new Error(\sprintf('DateTime cannot represent non date value: %s', Utils::printSafeJson($value)));
×
72
        }
73

74
        // Will be denormalized into a \DateTime.
75
        return $value;
×
76
    }
77

78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function parseLiteral(Node $valueNode, ?array $variables = null): string
82
    {
83
        if ($valueNode instanceof StringValueNode && false !== \DateTime::createFromFormat(\DateTime::ATOM, $valueNode->value)) {
×
84
            return $valueNode->value;
×
85
        }
86

87
        // Intentionally without message, as all information already in wrapped Exception
88
        throw new \Exception();
×
89
    }
90
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc