Skip to content

Commit bd7b9be

Browse files
committed
Fix cs and static analysis
1 parent 2678c9f commit bd7b9be

22 files changed

+177
-66
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
/vendor/
22
.phpunit.result.cache
3-
composer.lock
3+
composer.lock
4+
.php_cs.cache

.phive/phars.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phive xmlns="https://phar.io/phive">
3+
<phar name="psalm" version="^4.3.1" installed="4.8.1" location="./tools/psalm.phar" copy="true"/>
4+
<phar name="php-cs-fixer" version="^2.18.2" installed="2.19.0" location="./tools/php-cs-fixer.phar" copy="true"/>
5+
</phive>

.php_cs.dist

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?php
2+
3+
return PhpCsFixer\Config::create()
4+
->setFinder(
5+
\Symfony\Component\Finder\Finder::create()
6+
->in([
7+
__DIR__ . '/src',
8+
__DIR__ . '/tests',
9+
])
10+
->name('*.php')
11+
)
12+
->setRiskyAllowed(true)
13+
->setRules([
14+
'@PSR2' => true,
15+
'align_multiline_comment' => true,
16+
'array_indentation' => true,
17+
'declare_strict_types' => true,
18+
'final_class' => true,
19+
'global_namespace_import' => [
20+
'import_classes' => true,
21+
'import_constants' => true,
22+
'import_functions' => true,
23+
],
24+
'list_syntax' => [
25+
'syntax' => 'short',
26+
],
27+
'lowercase_constants' => true,
28+
'multiline_comment_opening_closing' => true,
29+
'native_function_casing' => true,
30+
'no_empty_phpdoc' => true,
31+
'no_leading_import_slash' => true,
32+
'no_superfluous_phpdoc_tags' => [
33+
'allow_mixed' => true,
34+
],
35+
'no_unused_imports' => true,
36+
'no_useless_else' => true,
37+
'no_useless_return' => true,
38+
'ordered_imports' => [
39+
'imports_order' => ['class', 'function', 'const'],
40+
],
41+
'ordered_interfaces' => true,
42+
'php_unit_test_annotation' => true,
43+
'php_unit_test_case_static_method_calls' => [
44+
'call_type' => 'static',
45+
],
46+
'php_unit_method_casing' => [
47+
'case' => 'snake_case',
48+
],
49+
'single_import_per_statement' => true,
50+
'single_trait_insert_per_statement' => true,
51+
'static_lambda' => true,
52+
'strict_comparison' => true,
53+
'strict_param' => true,
54+
])
55+
;

psalm.xml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0"?>
2+
<psalm
3+
errorLevel="1"
4+
resolveFromConfigFile="true"
5+
forbidEcho="true"
6+
strictBinaryOperands="true"
7+
phpVersion="8.0"
8+
allowPhpStormGenerics="true"
9+
allowStringToStandInForClass="true"
10+
rememberPropertyAssignmentsAfterCall="false"
11+
skipChecksOnUnresolvableIncludes="false"
12+
checkForThrowsDocblock="true"
13+
checkForThrowsInGlobalScope="true"
14+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
15+
xmlns="https://getpsalm.org/schema/config"
16+
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
17+
>
18+
<projectFiles>
19+
<directory name="src" />
20+
<ignoreFiles>
21+
<directory name="vendor" />
22+
<directory name="tests" />
23+
</ignoreFiles>
24+
</projectFiles>
25+
</psalm>

src/Builder/SoapHeaders.php

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,33 @@
1-
<?php
1+
<?php declare(strict_types=1);
22

33
namespace Soap\Xml\Builder;
44

55
use DOMElement;
66
use DOMNode;
7-
use Soap\Xml\Locator\SoapEnvelopeLocator;
87
use VeeWee\Xml\Dom\Builder\Builder;
98
use function VeeWee\Xml\Dom\Builder\namespaced_element;
109
use function VeeWee\Xml\Dom\Locator\Node\detect_document;
1110
use function VeeWee\Xml\Dom\Locator\root_namespace_uri;
1211

13-
class SoapHeaders implements Builder
12+
final class SoapHeaders implements Builder
1413
{
1514
/**
16-
* @var callable(DOMNode): DOMElement
15+
* @var list<callable(DOMNode): DOMElement>
1716
*/
1817
private array $configurators;
1918

2019
/**
21-
* @param callable(DOMNode): DOMElement ...$configurators
20+
* @no-named-arguments
21+
* @param list<callable(DOMNode): DOMElement> $configurators
2222
*/
2323
public function __construct(callable ... $configurators)
2424
{
2525
$this->configurators = $configurators;
2626
}
2727

2828
/**
29-
* @param DOMNode $node
29+
* @psalm-suppress MissingThrowsDocblock
30+
*
3031
* @param callable(DOMElement): DOMElement ...$configurators
3132
*/
3233
public function __invoke(DOMNode $node): DOMNode

src/Locator/BodyNamespaceLocator.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,17 @@
55
namespace Soap\Xml\Locator;
66

77
use DOMDocument;
8+
use VeeWee\Xml\Exception\RuntimeException;
89

910
final class BodyNamespaceLocator
1011
{
12+
/**
13+
* @psalm-suppress UndefinedPropertyFetch - psalm gets lost
14+
* @psalm-suppress MixedReturnStatement - psalm gets lost
15+
* @psalm-suppress MixedPropertyFetch - psalm gets lost
16+
* @psalm-suppress MixedInferredReturnType - psalm gets lost
17+
* @throws RuntimeException
18+
*/
1119
public function __invoke(DOMDocument $document): ?string
1220
{
1321
return (new SoapBodyLocator())($document)?->firstElementChild?->namespaceURI;

src/Locator/SoapBodyLocator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
use DOMDocument;
88
use DOMElement;
99
use VeeWee\Xml\Dom\Document;
10+
use VeeWee\Xml\Exception\RuntimeException;
1011
use function VeeWee\Xml\Dom\Locator\root_namespace_uri;
1112
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces;
1213

1314
final class SoapBodyLocator
1415
{
16+
/**
17+
* @throws RuntimeException
18+
*/
1519
public function __invoke(DOMDocument $document): ?DOMElement
1620
{
1721
$soapNs = root_namespace_uri()($document) ?? '';

src/Locator/SoapHeaderLocator.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,15 @@
77
use DOMDocument;
88
use DOMElement;
99
use VeeWee\Xml\Dom\Document;
10+
use VeeWee\Xml\Exception\RuntimeException;
1011
use function VeeWee\Xml\Dom\Locator\root_namespace_uri;
1112
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces;
1213

1314
final class SoapHeaderLocator
1415
{
16+
/**
17+
* @throws RuntimeException
18+
*/
1519
public function __invoke(DOMDocument $document): ?DOMElement
1620
{
1721
$soapNs = root_namespace_uri()($document) ?? '';

src/Manipulator/PrependSoapHeaders.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DOMElement;
99
use Soap\Xml\Locator\SoapEnvelopeLocator;
1010
use VeeWee\Xml\Dom\Document;
11+
use VeeWee\Xml\Exception\RuntimeException;
1112

1213
final class PrependSoapHeaders
1314
{
@@ -18,6 +19,11 @@ public function __construct(DOMElement $soapHeaders)
1819
$this->soapHeaders = $soapHeaders;
1920
}
2021

22+
/**
23+
* @throws RuntimeException
24+
* @psalm-suppress LessSpecificReturnStatement
25+
* @psalm-suppress MoreSpecificReturnType
26+
*/
2127
public function __invoke(DOMDocument $document): DOMElement
2228
{
2329
$doc = Document::fromUnsafeDocument($document);

src/Xpath/EnvelopePreset.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@
88
use Soap\Xml\Locator\BodyNamespaceLocator;
99
use VeeWee\Xml\Dom\Document;
1010
use VeeWee\Xml\Dom\Xpath\Configurator\Configurator;
11+
use VeeWee\Xml\Exception\RuntimeException;
1112
use function VeeWee\Xml\Dom\Locator\root_namespace_uri;
1213
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces;
1314

14-
class EnvelopePreset implements Configurator
15+
final class EnvelopePreset implements Configurator
1516
{
1617
private Document $document;
1718

@@ -20,6 +21,9 @@ public function __construct(Document $document)
2021
$this->document = $document;
2122
}
2223

24+
/**
25+
* @throws RuntimeException
26+
*/
2327
public function __invoke(DOMXPath $xpath): DOMXPath
2428
{
2529
return namespaces(array_filter([

src/Xpath/WsdlPreset.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
use function VeeWee\Xml\Dom\Locator\root_namespace_uri;
1111
use function VeeWee\Xml\Dom\Xpath\Configurator\namespaces;
1212

13-
class WsdlPreset implements Configurator
13+
final class WsdlPreset implements Configurator
1414
{
1515
private Document $document;
1616

@@ -21,8 +21,8 @@ public function __construct(Document $document)
2121

2222
public function __invoke(DOMXPath $xpath): DOMXPath
2323
{
24-
return namespaces([
24+
return namespaces(array_filter([
2525
'wsdl' => $this->document->locate(root_namespace_uri()),
26-
])($xpath);
26+
]))($xpath);
2727
}
2828
}

tests/Unit/Builder/SoapHeadersTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
use function VeeWee\Xml\Dom\Builder\value;
1212
use function VeeWee\Xml\Dom\Mapper\xml_string;
1313

14-
class SoapHeadersTest extends TestCase
14+
final class SoapHeadersTest extends TestCase
1515
{
16-
/** @test */
17-
public function it_can_create_a_header_element(): void
16+
17+
public function test_it_can_create_a_header_element(): void
1818
{
1919
$builder = new SoapHeaders(
2020
children(
@@ -32,7 +32,7 @@ public function it_can_create_a_header_element(): void
3232
</soap:Header>
3333
EOXML;
3434

35-
self::assertXmlStringEqualsXmlString(
35+
static::assertXmlStringEqualsXmlString(
3636
$expected,
3737
xml_string()($headers[0])
3838
);

tests/Unit/Locator/BodyNamespaceLocatorTest.php

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,34 @@
55

66
use PHPUnit\Framework\TestCase;
77
use Soap\Xml\Locator\BodyNamespaceLocator;
8-
use Soap\Xml\Locator\SoapBodyLocator;
98
use VeeWee\Xml\Dom\Document;
10-
use function VeeWee\Xml\Dom\Predicate\is_element;
119

12-
class BodyNamespaceLocatorTest extends TestCase
10+
final class BodyNamespaceLocatorTest extends TestCase
1311
{
14-
/** @test */
15-
public function it_detects_nothing_on_empty_envelope(): void
12+
13+
public function test_it_detects_nothing_on_empty_envelope(): void
1614
{
1715
$doc = Document::fromXmlFile(FIXTURE_DIR.'/empty-envelope.xml');
1816
$namespace = $doc->locate(new BodyNamespaceLocator());
1917

20-
self::assertNull($namespace);
18+
static::assertNull($namespace);
2119
}
2220

23-
/** @test */
24-
public function it_detects_nothing_on_empty_body(): void
21+
22+
public function test_it_detects_nothing_on_empty_body(): void
2523
{
2624
$doc = Document::fromXmlFile(FIXTURE_DIR.'/empty-envelope-with-body.xml');
2725
$namespace = $doc->locate(new BodyNamespaceLocator());
2826

29-
self::assertNull($namespace);
27+
static::assertNull($namespace);
3028
}
3129

32-
/** @test */
33-
public function it_detects_ns_on_body(): void
30+
31+
public function test_it_detects_ns_on_body(): void
3432
{
3533
$doc = Document::fromXmlFile(FIXTURE_DIR.'/envelope-with-body.xml');
3634
$namespace = $doc->locate(new BodyNamespaceLocator());
3735

38-
self::assertSame('http://tns.com', $namespace);
36+
static::assertSame('http://tns.com', $namespace);
3937
}
4038
}

tests/Unit/Locator/SoapBodyLocatorTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,24 @@
88
use VeeWee\Xml\Dom\Document;
99
use function VeeWee\Xml\Dom\Predicate\is_element;
1010

11-
class SoapBodyLocatorTest extends TestCase
11+
final class SoapBodyLocatorTest extends TestCase
1212
{
13-
/** @test */
14-
public function it_detects_nothing_on_empty_envelope(): void
13+
14+
public function test_it_detects_nothing_on_empty_envelope(): void
1515
{
1616
$doc = Document::fromXmlFile(FIXTURE_DIR.'/empty-envelope.xml');
1717
$body = $doc->locate(new SoapBodyLocator());
1818

19-
self::assertNull($body);
19+
static::assertNull($body);
2020
}
2121

22-
/** @test */
23-
public function it_detects_body_if_it_exists(): void
22+
23+
public function test_it_detects_body_if_it_exists(): void
2424
{
2525
$doc = Document::fromXmlFile(FIXTURE_DIR.'/empty-envelope-with-body.xml');
2626
$body = $doc->locate(new SoapBodyLocator());
2727

28-
self::assertTrue(is_element($body));
29-
self::assertSame('Body', $body->localName);
28+
static::assertTrue(is_element($body));
29+
static::assertSame('Body', $body->localName);
3030
}
3131
}

tests/Unit/Locator/SoapEnvelopeLocatorTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
use VeeWee\Xml\Dom\Document;
99
use function VeeWee\Xml\Dom\Predicate\is_element;
1010

11-
class SoapEnvelopeLocatorTest extends TestCase
11+
final class SoapEnvelopeLocatorTest extends TestCase
1212
{
13-
/** @test */
14-
public function it_detects_envelope(): void
13+
14+
public function test_it_detects_envelope(): void
1515
{
1616
$doc = Document::fromXmlFile(FIXTURE_DIR.'/empty-envelope.xml');
1717
$envelope = $doc->locate(new SoapEnvelopeLocator());
1818

19-
self::assertTrue(is_element($envelope));
20-
self::assertSame('Envelope', $envelope->localName);
19+
static::assertTrue(is_element($envelope));
20+
static::assertSame('Envelope', $envelope->localName);
2121
}
22-
}
22+
}

0 commit comments

Comments
 (0)