• 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/Entity/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\Entity;
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\ORM\Mapping as ORM;
21
use Symfony\Component\Serializer\Annotation\Groups;
22

23
#[ApiResource(normalizationContext: ['groups' => ['get_content']])]
24
#[ORM\Entity]
25
class Content implements \JsonSerializable
26
{
27
    #[ORM\Column(type: 'integer')]
28
    #[ORM\Id]
29
    #[ORM\GeneratedValue(strategy: 'AUTO')]
30
    private ?int $id = null;
31
    #[ORM\Column(type: 'string')]
32
    private string $contentType;
33
    /**
34
     * @var Collection<Field>
35
     */
36
    #[ORM\OneToMany(targetEntity: Field::class, mappedBy: 'content', cascade: ['persist'], orphanRemoval: true, indexBy: 'name')]
37
    #[ORM\OrderBy(['id' => 'ASC'])]
38
    private Collection|iterable $fields;
39
    #[ORM\Column(type: 'string')]
40
    // @noRector \Rector\Php81\Rector\Property\ReadOnlyPropertyRector
41
    private string $status = ContentStatus::DRAFT;
42

43
    public function __construct()
44
    {
45
        $this->fields = new ArrayCollection();
×
46
    }
47

48
    #[Groups(['get_content'])]
49
    public function getId(): ?int
50
    {
51
        return $this->id;
×
52
    }
53

54
    #[Groups(['get_content'])]
55
    public function getContentType(): ?string
56
    {
57
        return $this->contentType;
×
58
    }
59

60
    public function setContentType(string $contentType): void
61
    {
62
        $this->contentType = $contentType;
×
63
    }
64

65
    /**
66
     * @return array<string, Field>
67
     */
68
    public function getFields(): array
69
    {
70
        return $this->fields->toArray();
×
71
    }
72

73
    public function hasField(string $fieldName): bool
74
    {
75
        return isset($this->fields[$fieldName]);
×
76
    }
77

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

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

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

104
        return $fieldValues;
×
105
    }
106

107
    #[Groups(['get_content'])]
108
    public function getStatus(): ContentStatus
109
    {
110
        return new ContentStatus($this->status);
×
111
    }
112

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

© 2025 Coveralls, Inc