Skip to content

Prevent PHPStan error: 'Uuid::fromString() on a separate line has no effect.'#552

Merged
ramsey merged 2 commits intoramsey:4.xfrom
staabm:exc2
May 18, 2024
Merged

Prevent PHPStan error: 'Uuid::fromString() on a separate line has no effect.'#552
ramsey merged 2 commits intoramsey:4.xfrom
staabm:exc2

Conversation

@staabm
Copy link
Copy Markdown
Contributor

@staabm staabm commented May 12, 2024

Description

in a codebase which uses this lib like

<?php

require 'vendor/autoload.php';

function doFoo(string $id):void {
    try {
        \Ramsey\Uuid\Uuid::fromString($id);
    } catch (InvalidArgumentException) {
        throw new InvalidArgumentException('Invalid UUID string provided: ' . $id . '.');
    }
}

... and covers it with PHPStan, before this PR we ran into this error:

vendor/bin/phpstan analyze test.php --debug
Note: Using configuration file /Users/staabm/workspace/uuid/phpstan.neon.dist.
/Users/staabm/workspace/uuid/test.php
 ------ ---------------------------------------------------------------------------------------- 
  Line   test.php                                                                                
 ------ ---------------------------------------------------------------------------------------- 
  7      Call to static method Ramsey\Uuid\Uuid::fromString() on a separate line has no effect.  
 ------ ---------------------------------------------------------------------------------------- 


                                                                                                                        
 [ERROR] Found 1 error                                                                                                                                                                                                                     

after this PR the error is gone.

Motivation and context

fixes a PHPStan upstream reported ramsey/uuid issue: phpstan/phpstan#10819

How has this been tested?

locally by running the mentioned example with PHPStan

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

PR checklist

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING.md document.
  • I have added tests to cover my changes.

@staabm staabm requested a review from ramsey as a code owner May 12, 2024 07:22
@codecov
Copy link
Copy Markdown

codecov bot commented May 18, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 95.64%. Comparing base (d459bdb) to head (f5d65e2).
Report is 31 commits behind head on 4.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##                4.x     #552   +/-   ##
=========================================
  Coverage     95.64%   95.64%           
  Complexity      583      583           
=========================================
  Files            70       70           
  Lines          1560     1560           
=========================================
  Hits           1492     1492           
  Misses           68       68           
Files Coverage Δ
src/Uuid.php 98.01% <ø> (ø)

@ramsey
Copy link
Copy Markdown
Owner

ramsey commented May 18, 2024

Thank you for contributing! 🎉

@ramsey ramsey merged commit 558009c into ramsey:4.x May 18, 2024
@staabm staabm deleted the exc2 branch May 18, 2024 20:19
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.

2 participants