Skip to content

Commit fbc016f

Browse files
author
Christian Leucht
committed
Element // improve return types by using "static" instead of the specific class or implemented interface.
1 parent d52141d commit fbc016f

9 files changed

+51
-61
lines changed

phpunit.xml.dist

+19-29
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,21 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/6.3/phpunit.xsd"
5-
backupGlobals="false"
6-
backupStaticAttributes="false"
7-
bootstrap="tests/phpunit/bootstrap.php"
8-
colors="true"
9-
convertErrorsToExceptions="true"
10-
convertNoticesToExceptions="true"
11-
convertWarningsToExceptions="true"
12-
processIsolation="false"
13-
stopOnFailure="false">
14-
<testsuites>
15-
<testsuite name="Unit">
16-
<directory suffix="Test.php">tests/phpunit/Unit</directory>
17-
</testsuite>
18-
</testsuites>
19-
<filter>
20-
<whitelist processUncoveredFilesFromWhitelist="true">
21-
<directory suffix=".php">src</directory>
22-
<exclude>
23-
<directory>tests</directory>
24-
<directory>vendor</directory>
25-
</exclude>
26-
</whitelist>
27-
</filter>
28-
<logging>
29-
<log type="coverage-html" target="tmp"/>
30-
</logging>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" backupGlobals="false" backupStaticAttributes="false" bootstrap="tests/phpunit/bootstrap.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false">
3+
<coverage processUncoveredFiles="true">
4+
<include>
5+
<directory suffix=".php">src</directory>
6+
</include>
7+
<exclude>
8+
<directory>tests</directory>
9+
<directory>vendor</directory>
10+
</exclude>
11+
<report>
12+
<html outputDirectory="tmp"/>
13+
</report>
14+
</coverage>
15+
<testsuites>
16+
<testsuite name="Unit">
17+
<directory suffix="Test.php">tests/phpunit/Unit</directory>
18+
</testsuite>
19+
</testsuites>
20+
<logging/>
3121
</phpunit>

src/Element/ChoiceElement.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class ChoiceElement extends Element implements ChoiceElementInterface
1717
/**
1818
* @param ChoiceListInterface $list
1919
*
20-
* @return ChoiceElement
20+
* @return static
2121
*/
22-
public function withChoices(ChoiceListInterface $list): ChoiceElement
22+
public function withChoices(ChoiceListInterface $list): static
2323
{
2424
$this->list = $list;
2525

src/Element/CollectionElement.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ class CollectionElement extends Element implements CollectionElementInterface
3333
/**
3434
* @param ElementInterface[] $elements
3535
*
36-
* @return CollectionElement
36+
* @return static
3737
*/
38-
public function withElement(ElementInterface ...$elements): CollectionElement
38+
public function withElement(ElementInterface ...$elements): static
3939
{
4040
array_walk(
4141
$elements,
@@ -81,9 +81,9 @@ public function elementExists(string $name): bool
8181
* @param string $key
8282
* @param bool|int|string $value
8383
*
84-
* @return CollectionElement
84+
* @return static
8585
*/
86-
public function withAttribute(string $key, $value): ElementInterface
86+
public function withAttribute(string $key, $value): static
8787
{
8888
if ($key === 'value' && is_array($value)) {
8989
foreach ($this->elements as $name => $element) {
@@ -130,9 +130,9 @@ public function elements(): array
130130
*
131131
* @param array $errors
132132
*
133-
* @return CollectionElement
133+
* @return static
134134
*/
135-
public function withErrors(array $errors = []): CollectionElement
135+
public function withErrors(array $errors = []): static
136136
{
137137
$this->allErrors = $errors;
138138

src/Element/DescriptionAwareTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ public function description(): string
2121
/**
2222
* @param string $description
2323
*
24-
* @return self
24+
* @return static
2525
*/
26-
public function withDescription(string $description)
26+
public function withDescription(string $description): static
2727
{
2828
$this->description = $description;
2929

src/Element/Element.php

+14-14
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ public function __construct(string $name)
4444
* @param string $key
4545
* @param bool|int|string $value
4646
*
47-
* @return Element
47+
* @return static
4848
*/
49-
public function withAttribute(string $key, $value): ElementInterface
49+
public function withAttribute(string $key, $value): static
5050
{
5151
$this->attributes[$key] = $value;
5252

@@ -114,9 +114,9 @@ public function value()
114114
/**
115115
* @param string $value
116116
*
117-
* @return Element
117+
* @return static
118118
*/
119-
public function withValue($value): Element
119+
public function withValue($value): static
120120
{
121121
$this->withAttribute('value', $value);
122122

@@ -134,9 +134,9 @@ public function attributes(): array
134134
/**
135135
* @param array $attributes
136136
*
137-
* @return Element
137+
* @return static
138138
*/
139-
public function withAttributes(array $attributes = []): Element
139+
public function withAttributes(array $attributes = []): static
140140
{
141141
$this->attributes = array_merge(
142142
$this->attributes,
@@ -157,9 +157,9 @@ public function options(): array
157157
/**
158158
* @param array $options
159159
*
160-
* @return Element
160+
* @return static
161161
*/
162-
public function withOptions(array $options = []): Element
162+
public function withOptions(array $options = []): static
163163
{
164164
$this->options = array_merge(
165165
$this->options,
@@ -173,9 +173,9 @@ public function withOptions(array $options = []): Element
173173
* @param string $key
174174
* @param int|string $value
175175
*
176-
* @return Element
176+
* @return static
177177
*/
178-
public function withOption(string $key, $value): Element
178+
public function withOption(string $key, $value): static
179179
{
180180
$this->options[$key] = $value;
181181

@@ -199,9 +199,9 @@ public function option(string $key)
199199
/**
200200
* @param callable $callable
201201
*
202-
* @return $this
202+
* @return static
203203
*/
204-
public function withFilter(callable $callable): Element
204+
public function withFilter(callable $callable): static
205205
{
206206
$this->filter = $callable;
207207

@@ -220,9 +220,9 @@ public function filter($value)
220220
/**
221221
* @param callable $callable
222222
*
223-
* @return $this
223+
* @return static
224224
*/
225-
public function withValidator(callable $callable): Element
225+
public function withValidator(callable $callable): static
226226
{
227227
$this->validator = $callable;
228228

src/Element/ErrorAwareTrait.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ public function errors(): array
2626
/**
2727
* @param array $errors
2828
*
29-
* @return self
29+
* @return static
3030
*/
31-
public function withErrors(array $errors = [])
31+
public function withErrors(array $errors = []): static
3232
{
3333
$this->errors = array_merge($this->errors, $errors);
3434

src/Element/Form.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ class Form extends CollectionElement implements FormInterface
3434
* @param string $key
3535
* @param string|array $value
3636
*
37-
* @return ElementInterface
37+
* @return static
3838
* @throws LogicException
3939
*
4040
*/
41-
public function withAttribute(string $key, $value): ElementInterface
41+
public function withAttribute(string $key, $value): static
4242
{
4343
if ($key === 'value' && is_array($value)) {
4444
$this->withData($value);
@@ -52,11 +52,11 @@ public function withAttribute(string $key, $value): ElementInterface
5252
/**
5353
* @param array $data
5454
*
55-
* @return FormInterface
55+
* @return static
5656
* @throws LogicException
5757
*
5858
*/
59-
public function withData(array $data = []): FormInterface
59+
public function withData(array $data = []): static
6060
{
6161
if ($this->isSubmitted) {
6262
throw new LogicException('You cannot change data of a submitted form.');

src/Element/LabelAwareInterface.php

-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ public function labelAttributes(): array;
2222

2323
/**
2424
* @param array $labelAttributes
25-
*
26-
* @return self
2725
*/
2826
public function withLabelAttributes(array $labelAttributes = []);
2927
}

tests/phpunit/Unit/View/FormTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public function testRender(): void
4848
$expected_name = 'foo';
4949

5050
$element_stub = Mockery::mock(ElementInterface::class);
51+
$element_stub->allows('id')
52+
->andReturn($expected_name);
5153
$element_stub->allows('name')
5254
->andReturn($expected_name);
5355
$element_stub->allows('type')

0 commit comments

Comments
 (0)