Skip to content

Commit ecf93a2

Browse files
committed
Update codestyle
1 parent 8154f5b commit ecf93a2

11 files changed

+123
-133
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"inspirum/arrayable": "^1.2"
2929
},
3030
"require-dev": {
31-
"inspirum/coding-standard": "^1.4",
31+
"inspirum/coding-standard": "^1.5",
3232
"phpstan/phpstan": "^1.10",
3333
"phpunit/phpunit": "^10.5",
3434
"shipmonk/composer-dependency-analyser": "^1.5",

src/Builder/BaseNode.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ private function createFullDOMElement(string $name, mixed $value, array $attribu
143143

144144
private function createFullDOMElementFromNode(DOMNode $node, bool $forcedEscape = false, bool $withNamespaces = true): DOMElement
145145
{
146-
$value = null;
146+
$value = null;
147147
$childElements = [];
148148

149149
/** @var \DOMNode $child */
@@ -185,7 +185,7 @@ private function createDOMFragment(string $content): DOMDocumentFragment
185185
private function createDOMElementNS(string $name, ?string $value, bool $withNamespaces): DOMElement
186186
{
187187
$prefix = Parser::getNamespacePrefix($name);
188-
$value = Formatter::encodeValue($value);
188+
$value = Formatter::encodeValue($value);
189189

190190
if ($withNamespaces && $prefix !== null && $this->namespaceRegistry->hasNamespace($prefix)) {
191191
return $this->document->createElementNS($this->namespaceRegistry->getNamespace($prefix), $name, (string) $value);
@@ -223,7 +223,7 @@ private function setDOMElementValue(DOMElement $element, mixed $value, bool $for
223223
private function setDOMAttributeNS(DOMElement $element, string $name, mixed $value, bool $withNamespaces): void
224224
{
225225
$prefix = Parser::getNamespacePrefix($name);
226-
$value = Formatter::encodeValue($value);
226+
$value = Formatter::encodeValue($value);
227227

228228
if ($withNamespaces && $prefix === 'xmlns') {
229229
$element->setAttributeNS('http://www.w3.org/2000/xmlns/', $name, (string) $value);
@@ -288,7 +288,7 @@ private function getAttributesFromNode(DOMNode $node, bool $autoCast = false): a
288288
if ($node->hasAttributes()) {
289289
/** @var \DOMAttr $attribute */
290290
foreach ($node->attributes ?? [] as $attribute) {
291-
$value = $attribute->nodeValue;
291+
$value = $attribute->nodeValue;
292292
$attributes[$attribute->nodeName] = $autoCast ? Formatter::decodeValue($value) : $value;
293293
}
294294
}

src/Formatter/BaseConfig.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@
66

77
abstract readonly class BaseConfig implements Config
88
{
9-
private const ATTRIBUTES = '@attributes';
10-
private const NODES = '@nodes';
11-
private const VALUE = '@value';
12-
private const FLATTEN_NODES = '/';
9+
private const ATTRIBUTES = '@attributes';
10+
private const NODES = '@nodes';
11+
private const VALUE = '@value';
12+
private const FLATTEN_NODES = '/';
1313
private const FLATTEN_ATTRIBUTES = '@';
1414

1515
/**

src/Formatter/Formatter.php

+3-12
Original file line numberDiff line numberDiff line change
@@ -68,10 +68,6 @@ public static function encodeValue(mixed $value): ?string
6868

6969
/**
7070
* Normalize value.
71-
*
72-
* @param mixed $value
73-
*
74-
* @return mixed
7571
*/
7672
public static function decodeValue(mixed $value): mixed
7773
{
@@ -92,11 +88,6 @@ public static function decodeValue(mixed $value): mixed
9288

9389
/**
9490
* Convert DOM node to array
95-
*
96-
* @param \DOMNode $node
97-
* @param \Inspirum\XML\Formatter\Config $config
98-
*
99-
* @return mixed
10091
*/
10192
public static function nodeToArray(DOMNode $node, Config $config): mixed
10293
{
@@ -145,8 +136,8 @@ private static function nodeToArrayRecursive(DOMNode $node, Config $config, int
145136
if ($config->isFullResponse()) {
146137
return [
147138
$config->getAttributesName() => $attributes,
148-
$config->getValueName() => $value,
149-
$config->getNodesName() => $nodes,
139+
$config->getValueName() => $value,
140+
$config->getNodesName() => $nodes,
150141
];
151142
}
152143

@@ -173,7 +164,7 @@ private static function flattenArray(array &$nodes, string $nodeNames, mixed $ch
173164
foreach ($childNodes as $childNodeName => $childNodeValues) {
174165
if ($childNodeName === $config->getAttributesName() && is_array($childNodeValues)) {
175166
foreach ($childNodeValues as $attributeName => $attributeValue) {
176-
$nodeKey = sprintf('%s%s%s', $nodeNames, $config->getFlattenAttributes(), $attributeName);
167+
$nodeKey = sprintf('%s%s%s', $nodeNames, $config->getFlattenAttributes(), $attributeName);
177168
$nodes[$nodeKey][] = $attributeValue;
178169
}
179170
} elseif ($childNodeName === $config->getValueName()) {

src/Reader/DefaultReader.php

+11-12
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ public function close(): void
8080
*/
8181
private function moveToNode(string $nodeName): MoveResult
8282
{
83-
$usePath = str_starts_with($nodeName, '/');
84-
$paths = explode('/', ltrim($nodeName, '/'));
83+
$usePath = str_starts_with($nodeName, '/');
84+
$paths = explode('/', ltrim($nodeName, '/'));
8585
$maxDepth = count($paths) - 1;
8686

8787
$namespaces = [];
@@ -123,7 +123,7 @@ private function moveToNode(string $nodeName): MoveResult
123123
*/
124124
private function readNode(?array $rootNamespaces = null): ReadResult
125125
{
126-
$name = $this->getNodeName();
126+
$name = $this->getNodeName();
127127
$attributes = $this->getNodeAttributes();
128128
$namespaces = Parser::parseNamespaces($attributes);
129129

@@ -133,7 +133,7 @@ private function readNode(?array $rootNamespaces = null): ReadResult
133133

134134
/** @var list<\Inspirum\XML\Reader\ReadResult> $elements */
135135
$elements = [];
136-
$text = null;
136+
$text = null;
137137

138138
while ($this->read()) {
139139
if ($this->isNodeElementEndType() && $this->getNodeName() === $name) {
@@ -153,8 +153,8 @@ private function readNode(?array $rootNamespaces = null): ReadResult
153153
}
154154

155155
/**
156-
* @param array<string,string> $attributes
157-
* @param array<string,string> $namespaces
156+
* @param array<string,string> $attributes
157+
* @param array<string,string> $namespaces
158158
* @param array<string,string>|null $rootNamespaces
159159
*/
160160
private function createEmptyNode(string $name, array $attributes, array $namespaces, ?array $rootNamespaces): ReadResult
@@ -163,18 +163,18 @@ private function createEmptyNode(string $name, array $attributes, array $namespa
163163
}
164164

165165
/**
166-
* @param array<string,string> $attributes
167-
* @param array<string,string> $namespaces
168-
* @param array<string,string>|null $rootNamespaces
169-
* @param list<\Inspirum\XML\Reader\ReadResult> $elements
166+
* @param array<string,string> $attributes
167+
* @param array<string,string> $namespaces
168+
* @param array<string,string>|null $rootNamespaces
169+
* @param list<\Inspirum\XML\Reader\ReadResult> $elements
170170
*
171171
* @throws \DOMException
172172
*/
173173
private function createNode(string $name, mixed $text, array $attributes, array $namespaces, ?array $rootNamespaces, array $elements): ReadResult
174174
{
175175
$usedNamespaces = $this->getUsedNamespaces($name, $attributes);
176176

177-
$namespaces = array_merge($namespaces, ...array_map(static fn(ReadResult $element) => $element->namespaces, $elements));
177+
$namespaces = array_merge($namespaces, ...array_map(static fn(ReadResult $element) => $element->namespaces, $elements));
178178
$usedNamespaces = array_merge($usedNamespaces, ...array_map(static fn(ReadResult $element) => $element->usedNamespaces, $elements));
179179

180180
$withNamespace = $rootNamespaces !== null;
@@ -200,7 +200,6 @@ private function createNode(string $name, mixed $text, array $attributes, array
200200
}
201201

202202
/**
203-
* @param string $name
204203
* @param array<string,string> $attributes
205204
*
206205
* @return list<string>

src/Reader/DefaultReaderFactory.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function __construct(
2222
public function create(string $filepath, ?string $version = null, ?string $encoding = null, ?int $flags = null): Reader
2323
{
2424
$xmlReader = $this->readerFactory->create();
25-
$document = $this->documentFactory->create($version, $encoding);
25+
$document = $this->documentFactory->create($version, $encoding);
2626

2727
Handler::withErrorHandlerForXMLReader(static function () use ($xmlReader, $filepath, $encoding, $flags): void {
2828
$opened = $xmlReader->open($filepath, $encoding, $flags ?? 0);

src/Reader/ReadResult.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ final class ReadResult
1313
{
1414
/**
1515
* @param array<string,string> $namespaces
16-
* @param list<string> $usedNamespaces
16+
* @param list<string> $usedNamespaces
1717
*/
1818
private function __construct(
1919
public readonly Node $node,
@@ -24,7 +24,7 @@ private function __construct(
2424

2525
/**
2626
* @param array<string,string> $namespaces
27-
* @param list<string> $usedNamespaces
27+
* @param list<string> $usedNamespaces
2828
*/
2929
public static function create(Node $node, array $namespaces = [], array $usedNamespaces = []): self
3030
{

tests/Builder/DefaultDocumentFactoryTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class DefaultDocumentFactoryTest extends BaseTestCase
1717
public function testDefaultVersionAndEncoding(): void
1818
{
1919
$factory = $this->newDocumentFactory();
20-
$xml = $factory->create();
20+
$xml = $factory->create();
2121

2222
self::assertSame(
2323
'<?xml version="1.0" encoding="UTF-8"?>' . "\n",
@@ -28,7 +28,7 @@ public function testDefaultVersionAndEncoding(): void
2828
public function testVersionAndEncoding(): void
2929
{
3030
$factory = $this->newDocumentFactory();
31-
$xml = $factory->create('1.1', 'WINDOWS-1250');
31+
$xml = $factory->create('1.1', 'WINDOWS-1250');
3232

3333
self::assertSame(
3434
'<?xml version="1.1" encoding="WINDOWS-1250"?>' . "\n",
@@ -39,7 +39,7 @@ public function testVersionAndEncoding(): void
3939
public function testCreateForContentMethod(): void
4040
{
4141
$factory = $this->newDocumentFactory();
42-
$xml = $factory->createForContent('<?xml version="1.0" encoding="UTF-8"?><root><a><b1>1</b1><b2>test</b2></a></root>');
42+
$xml = $factory->createForContent('<?xml version="1.0" encoding="UTF-8"?><root><a><b1>1</b1><b2>test</b2></a></root>');
4343

4444
self::assertSame(
4545
'<?xml version="1.0" encoding="UTF-8"?>' . "\n" . '<root><a><b1>1</b1><b2>test</b2></a></root>' . "\n",
@@ -75,7 +75,7 @@ public function testCreateForContentMethodWithInvalidXml2(): void
7575
public function testCreateForContentMethodFromFile(): void
7676
{
7777
$factory = $this->newDocumentFactory();
78-
$xml = $factory->createForContent(self::loadSampleFilepath('sample_01.xml'));
78+
$xml = $factory->createForContent(self::loadSampleFilepath('sample_01.xml'));
7979

8080
self::assertSame(
8181
self::getSampleXMLString('<root><a><b1>1</b1><b2>test</b2></a><a><b1>2</b1><b2>test2</b2><b3>true</b3></a><b><a><b1>3</b1><b3>false</b3></a></b></root>'),
@@ -86,7 +86,7 @@ public function testCreateForContentMethodFromFile(): void
8686
public function testCreateForFileMethodFromFile(): void
8787
{
8888
$factory = $this->newDocumentFactory();
89-
$xml = $factory->createForFile(self::getTestFilePath('sample_01.xml'));
89+
$xml = $factory->createForFile(self::getTestFilePath('sample_01.xml'));
9090

9191
self::assertSame(
9292
self::getSampleXMLString('<root><a><b1>1</b1><b2>test</b2></a><a><b1>2</b1><b2>test2</b2><b3>true</b3></a><b><a><b1>3</b1><b3>false</b3></a></b></root>'),

tests/Builder/DefaultDocumentTest.php

+18-18
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,9 @@ public function testGetNamespaceURIs(): void
227227
$xml->addElement('rss', [
228228
'xmlns:a' => 'a.xsd',
229229
'xmlns:b' => 'b.xsd',
230-
'xmlnse' => 'e.xsd',
231-
'xmlns' => 'default.xsd',
232-
'a:test' => '1',
230+
'xmlnse' => 'e.xsd',
231+
'xmlns' => 'default.xsd',
232+
'a:test' => '1',
233233
]);
234234

235235
self::assertSame(
@@ -248,7 +248,7 @@ public function testGetNamespaceURI(): void
248248

249249
$xml->addElement('rss', [
250250
'xmlns:a' => 'a.xsd',
251-
'xmlns' => 'default.xsd',
251+
'xmlns' => 'default.xsd',
252252
]);
253253

254254
self::assertSame('a.xsd', $xml->getNamespace('a'));
@@ -308,7 +308,7 @@ public function testAttributeEmptyName(): void
308308

309309
$xml->addElement('rss', [
310310
'a:a' => '1',
311-
'a:' => '2',
311+
'a:' => '2',
312312
]);
313313
}
314314

@@ -321,7 +321,7 @@ public function testAttributeEmptyPrefix(): void
321321

322322
$xml->addElement('rss', [
323323
'a:a' => '1',
324-
':a' => '2',
324+
':a' => '2',
325325
]);
326326
}
327327

@@ -411,10 +411,10 @@ public function testDefaultXmlnsAttributes(): void
411411

412412
public function testValidateXsd(): void
413413
{
414-
$xml = $this->newDocument();
414+
$xml = $this->newDocument();
415415
$feed = $xml->addElement('g:feed', [
416416
'g:version' => '2.0',
417-
'xmlns:g' => 'stock.xsd',
417+
'xmlns:g' => 'stock.xsd',
418418
]);
419419

420420
$feed->addTextElement('g:updated', '2020-08-25T13:53:38+00:00');
@@ -437,10 +437,10 @@ public function testValidateXsdFromOutput(): void
437437
{
438438
$this->expectNotToPerformAssertions();
439439

440-
$xml = $this->newDocument();
440+
$xml = $this->newDocument();
441441
$feed = $xml->addElement('g:feed', [
442442
'g:version' => '2.0',
443-
'xmlns:g' => 'stock.xsd',
443+
'xmlns:g' => 'stock.xsd',
444444
]);
445445

446446
$feed->addTextElement('g:updated', '2020-08-25T13:53:38+00:00');
@@ -480,7 +480,7 @@ public function testValidateWithoutXmlns(): void
480480
{
481481
$this->expectException(DOMException::class);
482482

483-
$xml = $this->newDocument();
483+
$xml = $this->newDocument();
484484
$feed = $xml->addElement('g:feed', [
485485
'g:version' => '2.0',
486486
]);
@@ -500,7 +500,7 @@ public function testValidateWithoutAttributePrefix(): void
500500
{
501501
$this->expectException(DOMException::class);
502502

503-
$xml = $this->newDocument();
503+
$xml = $this->newDocument();
504504
$feed = $xml->addElement('g:feed', [
505505
'version' => '2.0',
506506
'xmlns:g' => 'stock.xsd',
@@ -521,7 +521,7 @@ public function testValidateWithoutElementPrefix(): void
521521
{
522522
$this->expectException(DOMException::class);
523523

524-
$xml = $this->newDocument();
524+
$xml = $this->newDocument();
525525
$feed = $xml->addElement('feed', [
526526
'version' => '2.0',
527527
'xmlns:g' => 'stock.xsd',
@@ -542,10 +542,10 @@ public function testValidateInvalidXml(): void
542542
{
543543
$this->expectException(DOMException::class);
544544

545-
$xml = $this->newDocument();
545+
$xml = $this->newDocument();
546546
$feed = $xml->addElement('g:feed', [
547547
'g:version' => '2.0',
548-
'xmlns:g' => 'stock.xsd',
548+
'xmlns:g' => 'stock.xsd',
549549
]);
550550

551551
$items = $feed->addElement('g:items');
@@ -561,7 +561,7 @@ public function testValidateInvalidXml(): void
561561
public function testFormattedOutput(): void
562562
{
563563
$factory = $this->newDocumentFactory();
564-
$xml = $factory->createForContent('<?xml version="1.0" encoding="UTF-8"?><root><a><b1>1</b1><b2>test</b2></a></root>');
564+
$xml = $factory->createForContent('<?xml version="1.0" encoding="UTF-8"?><root><a><b1>1</b1><b2>test</b2></a></root>');
565565

566566
self::assertSame(
567567
self::getSampleXMLString(
@@ -581,7 +581,7 @@ public function testFormattedOutput(): void
581581
public function testSaveMethod(): void
582582
{
583583
$factory = $this->newDocumentFactory();
584-
$xml = $factory->createForFile(self::getTestFilePath('sample_01.xml'));
584+
$xml = $factory->createForFile(self::getTestFilePath('sample_01.xml'));
585585

586586
$name = (string) tempnam(sys_get_temp_dir(), 'xml_tests_');
587587
self::assertSame('', file_get_contents($name));
@@ -597,7 +597,7 @@ public function testSaveMethod(): void
597597
public function testSaveMethodWithFormatOutput(): void
598598
{
599599
$factory = $this->newDocumentFactory();
600-
$xml = $factory->createForFile(self::getTestFilePath('sample_01.xml'));
600+
$xml = $factory->createForFile(self::getTestFilePath('sample_01.xml'));
601601

602602
$name = (string) tempnam(sys_get_temp_dir(), 'xml_tests_');
603603
self::assertSame('', file_get_contents($name));

0 commit comments

Comments
 (0)