• 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/Document/Content.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\Document;
15

16
use ApiPlatform\Metadata\ApiResource;
17
use ApiPlatform\Tests\Fixtures\TestBundle\Enum\ContentStatus;
18
use Doctrine\Common\Collections\ArrayCollection;
19
use Doctrine\Common\Collections\Collection;
20
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
21
use Symfony\Component\Serializer\Annotation\Groups;
22

23
#[ApiResource(normalizationContext: ['groups' => ['get_content']])]
24
#[ODM\Document]
25
class Content implements \JsonSerializable
26
{
27
    #[ODM\Id(strategy: 'INCREMENT', type: 'int')]
28
    private ?int $id = null;
29
    #[ODM\Field(type: 'string')]
30
    private string $contentType;
31
    /**
32
     * @var Collection<Field>
33
     */
34
    #[ODM\ReferenceMany(targetDocument: Field::class, mappedBy: 'content', strategy: 'set', cascade: ['persist'])]
35
    private Collection|iterable $fields;
36
    #[ODM\Field(type: 'string')]
37
    private string $status = ContentStatus::DRAFT;
38

39
    public function __construct()
40
    {
41
        $this->fields = new ArrayCollection();
×
42
    }
43

44
    #[Groups(['get_content'])]
45
    public function getId(): ?int
46
    {
47
        return $this->id;
×
48
    }
49

50
    #[Groups(['get_content'])]
51
    public function getContentType(): ?string
52
    {
53
        return $this->contentType;
×
54
    }
55

56
    public function setContentType(string $contentType): void
57
    {
58
        $this->contentType = $contentType;
×
59
    }
60

61
    /**
62
     * @return array<string, Field>
63
     */
64
    public function getFields(): array
65
    {
66
        return $this->fields->toArray();
×
67
    }
68

69
    public function hasField(string $fieldName): bool
70
    {
71
        return isset($this->fields[$fieldName]);
×
72
    }
73

74
    public function addField(Field $field): void
75
    {
76
        if ($this->hasField($field->getName())) {
×
NEW
77
            throw new \InvalidArgumentException(\sprintf("Content already has '%s' field", $field->getName()));
×
78
        }
79
        $this->fields[$field->getName()] = $field;
×
80
        $field->setContent($this);
×
81
    }
82

83
    public function removeField(Field $field): void
84
    {
85
        unset($this->fields[$field->getName()]);
×
86
        // set the owning side to null (unless already changed)
87
        if ($field->getContent() === $this) {
×
88
            $field->setContent(null);
×
89
        }
90
    }
91

92
    #[Groups(['get_content'])]
93
    public function getFieldValues(): array
94
    {
95
        $fieldValues = [];
×
96
        foreach ($this->getFields() as $field) {
×
97
            $fieldValues[$field->getName()] = $field->getValue();
×
98
        }
99

100
        return $fieldValues;
×
101
    }
102

103
    #[Groups(['get_content'])]
104
    public function getStatus(): ContentStatus
105
    {
106
        return new ContentStatus($this->status);
×
107
    }
108

109
    /**
110
     * {@inheritdoc}
111
     */
112
    public function jsonSerialize(): array
113
    {
114
        return ['id' => $this->id, 'contentType' => $this->contentType, 'fields' => $this->fields];
×
115
    }
116
}
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