Skip to content

Commit 251e970

Browse files
committed
Apply coding standard
1 parent 0d41a1c commit 251e970

11 files changed

Lines changed: 177 additions & 194 deletions

psalm-baseline.xml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<code><![CDATA[$name[0]]]></code>
2020
</MixedArrayAccess>
2121
<PossiblyInvalidArgument>
22-
<code><![CDATA[fn(DOMNode $node) => $this->readJson($node->textContent, $url)]]></code>
22+
<code><![CDATA[fn (DOMNode $node) => $this->readJson($node->textContent, $url)]]></code>
2323
</PossiblyInvalidArgument>
2424
<RawObjectIteration>
2525
<code><![CDATA[$item]]></code>
@@ -30,8 +30,8 @@
3030
</file>
3131
<file src="src/Reader/MicrodataReader.php">
3232
<InvalidArgument>
33-
<code><![CDATA[function(DOMNode $itemprop) use ($node, $xpath) {
34-
for (;;) {
33+
<code><![CDATA[function (DOMNode $itemprop) use ($node, $xpath) {
34+
for (; ;) {
3535
$itemprop = $itemprop->parentNode;
3636
3737
if ($itemprop->isSameNode($node)) {
@@ -45,9 +45,9 @@
4545
}]]></code>
4646
</InvalidArgument>
4747
<PossiblyInvalidArgument>
48-
<code><![CDATA[fn(DOMNode $node) => $this->nodeToItem($node, $xpath, $url)]]></code>
49-
<code><![CDATA[function(DOMNode $itemprop) use ($node, $xpath) {
50-
for (;;) {
48+
<code><![CDATA[fn (DOMNode $node) => $this->nodeToItem($node, $xpath, $url)]]></code>
49+
<code><![CDATA[function (DOMNode $itemprop) use ($node, $xpath) {
50+
for (; ;) {
5151
$itemprop = $itemprop->parentNode;
5252
5353
if ($itemprop->isSameNode($node)) {
@@ -77,8 +77,8 @@
7777
</file>
7878
<file src="src/Reader/RdfaLiteReader.php">
7979
<InvalidArgument>
80-
<code><![CDATA[function(DOMNode $itemprop) use ($node, $xpath) {
81-
for (;;) {
80+
<code><![CDATA[function (DOMNode $itemprop) use ($node, $xpath) {
81+
for (; ;) {
8282
$itemprop = $itemprop->parentNode;
8383
8484
if ($itemprop->isSameNode($node)) {
@@ -95,9 +95,9 @@
9595
}]]></code>
9696
</InvalidArgument>
9797
<PossiblyInvalidArgument>
98-
<code><![CDATA[fn(DOMNode $node) => $this->nodeToItem($node, $xpath, $url, self::PREDEFINED_PREFIXES, null)]]></code>
99-
<code><![CDATA[function(DOMNode $itemprop) use ($node, $xpath) {
100-
for (;;) {
98+
<code><![CDATA[fn (DOMNode $node) => $this->nodeToItem($node, $xpath, $url, self::PREDEFINED_PREFIXES, null)]]></code>
99+
<code><![CDATA[function (DOMNode $itemprop) use ($node, $xpath) {
100+
for (; ;) {
101101
$itemprop = $itemprop->parentNode;
102102
103103
if ($itemprop->isSameNode($node)) {

src/DOMBuilder.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66

77
use DOMDocument;
88

9+
use const LIBXML_NOERROR;
10+
use const LIBXML_NOWARNING;
11+
912
final class DOMBuilder
1013
{
1114
/**
1215
* Builds a DOMDocument from an HTML string.
13-
*
14-
* @param string $html
15-
*
16-
* @return DOMDocument
1716
*/
18-
public static function fromHTML(string $html) : DOMDocument
17+
public static function fromHTML(string $html): DOMDocument
1918
{
2019
$document = new DOMDocument();
2120
$document->loadHTML($html, LIBXML_NOWARNING | LIBXML_NOERROR);
@@ -25,12 +24,8 @@ public static function fromHTML(string $html) : DOMDocument
2524

2625
/**
2726
* Builds a DOMDocument from an HTML file.
28-
*
29-
* @param string $file
30-
*
31-
* @return DOMDocument
3227
*/
33-
public static function fromHTMLFile(string $file) : DOMDocument
28+
public static function fromHTMLFile(string $file): DOMDocument
3429
{
3530
$document = new DOMDocument();
3631
$document->loadHTMLFile($file, LIBXML_NOWARNING | LIBXML_NOERROR);

src/HTMLReader.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ final class HTMLReader
1010

1111
/**
1212
* HTMLReader constructor.
13-
*
14-
* @param Reader $reader
1513
*/
1614
public function __construct(Reader $reader)
1715
{
@@ -27,7 +25,7 @@ public function __construct(Reader $reader)
2725
*
2826
* @return Item[] The top-level items.
2927
*/
30-
public function read(string $html, string $url) : array
28+
public function read(string $html, string $url): array
3129
{
3230
$document = DOMBuilder::fromHTML($html);
3331

@@ -43,7 +41,7 @@ public function read(string $html, string $url) : array
4341
*
4442
* @return Item[] The top-level items.
4543
*/
46-
public function readFile(string $file, string $url) : array
44+
public function readFile(string $file, string $url): array
4745
{
4846
$document = DOMBuilder::fromHTMLFile($file);
4947

src/Item.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,14 @@ final class Item
3636
*/
3737
public function __construct(?string $id, string ...$types)
3838
{
39-
$this->id = $id;
39+
$this->id = $id;
4040
$this->types = $types;
4141
}
4242

4343
/**
4444
* Returns the global identifier of the item, if any.
45-
*
46-
* @return string|null
4745
*/
48-
public function getId() : ?string
46+
public function getId(): ?string
4947
{
5048
return $this->id;
5149
}
@@ -57,7 +55,7 @@ public function getId() : ?string
5755
*
5856
* @return string[]
5957
*/
60-
public function getTypes() : array
58+
public function getTypes(): array
6159
{
6260
return $this->types;
6361
}
@@ -70,7 +68,7 @@ public function getTypes() : array
7068
*
7169
* @return array<string, array<Item|string>>
7270
*/
73-
public function getProperties() : array
71+
public function getProperties(): array
7472
{
7573
return $this->properties;
7674
}
@@ -81,22 +79,14 @@ public function getProperties() : array
8179
* The result is a list of Item instances or plain strings.
8280
* If the property does not exist, an empty array is returned.
8381
*
84-
* @param string $name
85-
*
8682
* @return array<Item|string>
8783
*/
88-
public function getProperty(string $name) : array
84+
public function getProperty(string $name): array
8985
{
9086
return $this->properties[$name] ?? [];
9187
}
9288

93-
/**
94-
* @param string $name
95-
* @param Item|string $value
96-
*
97-
* @return void
98-
*/
99-
public function addProperty(string $name, Item|string $value) : void
89+
public function addProperty(string $name, Item|string $value): void
10090
{
10191
$this->properties[$name][] = $value;
10292
}

src/JsonLdWriter.php

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@
44

55
namespace Brick\StructuredData;
66

7+
use function array_map;
8+
use function count;
9+
use function json_encode;
10+
11+
use const JSON_PRETTY_PRINT;
12+
use const JSON_THROW_ON_ERROR;
13+
use const JSON_UNESCAPED_SLASHES;
14+
715
/**
816
* Exports Items to JSON-LD.
917
*/
@@ -12,14 +20,12 @@ final class JsonLdWriter
1220
/**
1321
* Exports a list of Items as JSON-LD.
1422
*
15-
* @param Item ...$items
16-
*
1723
* @return string The JSON-LD representation.
1824
*/
19-
public function write(Item ...$items) : string
25+
public function write(Item ...$items): string
2026
{
2127
$items = array_map(
22-
fn(Item $item) => $this->convertItem($item),
28+
fn (Item $item) => $this->convertItem($item),
2329
$items,
2430
);
2531

@@ -28,15 +34,11 @@ public function write(Item ...$items) : string
2834

2935
/**
3036
* Converts an Item to an associative array that can be encoded with json_encode().
31-
*
32-
* @param Item $item
33-
*
34-
* @return array
3537
*/
36-
private function convertItem(Item $item) : array
38+
private function convertItem(Item $item): array
3739
{
3840
$result = [
39-
'@type' => $this->extractIfSingle($item->getTypes())
41+
'@type' => $this->extractIfSingle($item->getTypes()),
4042
];
4143

4244
if ($item->getId() !== null) {
@@ -58,12 +60,8 @@ private function convertItem(Item $item) : array
5860

5961
/**
6062
* Returns the value from a list containing a single value, or the array if it does not contain exactly one value.
61-
*
62-
* @param array $values
63-
*
64-
* @return mixed
6563
*/
66-
private function extractIfSingle(array $values) : mixed
64+
private function extractIfSingle(array $values): mixed
6765
{
6866
if (count($values) === 1) {
6967
return $values[0];

src/Reader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ interface Reader
2020
*
2121
* @return Item[] The top-level items.
2222
*/
23-
public function read(DOMDocument $document, string $url) : array;
23+
public function read(DOMDocument $document, string $url): array;
2424
}

0 commit comments

Comments
 (0)