Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update dependencies and tooling #173

Merged
merged 5 commits into from
Jan 29, 2020
Merged

Update dependencies and tooling #173

merged 5 commits into from
Jan 29, 2020

Conversation

phil-davis
Copy link
Contributor

@phil-davis phil-davis commented Jan 29, 2020

  • drop PHP 7.0
  • move to phpunit 7
  • use later phpstan
  • run php-cs-fixer in CI

@phil-davis phil-davis self-assigned this Jan 29, 2020
@phil-davis
Copy link
Contributor Author

The newer version of phpstan reports:

------ ------------------------------------------------------- 

  Line   Reader.php                                             

 ------ ------------------------------------------------------- 

  187    Unreachable statement - code above always terminates.  

 ------ ------------------------------------------------------- 

 ------ ---------------------------------------------------------------------- 

  Line   Serializer/functions.php                                              

 ------ ---------------------------------------------------------------------- 

  167    Call to function is_null() with array|object will always evaluate to  

         false.                                                                

         💡 Because the type is coming from a PHPDoc, you can turn off this     

         check by setting treatPhpDocTypesAsCertain: false in your             

         /home/travis/build/sabre-io/xml/phpstan.neon.                         

 ------ ---------------------------------------------------------------------- 

 ------ ----------------------------------------------------------------- 

  Line   Writer.php                                                       

 ------ ----------------------------------------------------------------- 

  130    Parameter #3 $uri of method XMLWriter::startElementNs() expects  

         string, null given.                                              

 ------ ----------------------------------------------------------------- 

                                                                                

 [ERROR] Found 3 errors                                                         

I am looking at those.

@codecov
Copy link

codecov bot commented Jan 29, 2020

Codecov Report

Merging #173 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff            @@
##             master     #173   +/-   ##
=========================================
  Coverage     97.61%   97.61%           
+ Complexity      114      112    -2     
=========================================
  Files            13       13           
  Lines           461      461           
=========================================
  Hits            450      450           
  Misses           11       11
Impacted Files Coverage Δ Complexity Δ
lib/Writer.php 100% <ø> (ø) 19 <0> (ø) ⬇️
lib/Service.php 100% <ø> (ø) 18 <0> (-2) ⬇️
lib/LibXMLException.php 100% <ø> (ø) 2 <0> (ø) ⬇️
lib/Serializer/functions.php 100% <100%> (ø) 0 <0> (ø) ⬇️
lib/Reader.php 99.13% <100%> (+0.01%) 43 <0> (ø) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cb14cf1...55a064f. Read the comment docs.

@@ -169,7 +171,8 @@ public function parseInnerTree(array $elementMap = null)
case self::END_ELEMENT:
// Ensuring we are moving the cursor after the end element.
$this->read();
break 2;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This break 2 was causing phpstan to report:

Line 187    Unreachable statement - code above always terminates.

phpstan seems to not realise that break 2 is a way out of both the switch and while statements.

It is easy enough to refactor the code to have a boolean to control the while loop. And maybe that makes it easier to read?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should report a upstream issue.. in case you dont want/don't have time to do it, i will do it.

just let me know.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@staabm you know better exactly about upstream. Please report.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do. thx.

IMO the newly introduced logic is better to read, because its now obvious what this single spot is trying to achieve. the break 2 could also be read as a mistake

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -165,8 +164,6 @@ function standardSerializer(Writer $writer, $value)
} elseif (is_callable($value)) {
// A callback
$value($writer);
} elseif (is_null($value)) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan complains:

167    Call to function is_null() with array|object will always evaluate to false

It knows that $value at this point might be an array or object.

After looking at the code, there are elseif cases below that explicitly handle the array and object cases. So I refactored so that is_null() is not needed here.

bootstrap: %currentWorkingDirectory%/vendor/autoload.php
ignoreErrors:
-
message: '!Parameter #3 \$uri of method XMLWriter::startElementNs\(\) expects string, null given.!'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

phpstan complains:

130    Parameter #3 $uri of method XMLWriter::startElementNs() expects string, null given.

The code is:

                $result = $this->startElementNS(
                    '' === $this->namespaceMap[$namespace] ? null : $this->namespaceMap[$namespace],
                    $localName,
                    null
                );

Actually phpstan is correct - startElementNS is supposed to take a string and not allow null to be passed.

But also I found https://www.php.net/manual/en/function.xmlwriter-start-element-ns.php#76920

If you don't want any namespace prefix at all but still want the xmlns attribute, set $prefix to null.

So I ignored this phpstan error, rather than "fixing" the code.

@phil-davis phil-davis marked this pull request as ready for review January 29, 2020 09:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants