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

False positive - Class pending was referenced relatively but not defined #12

Open
phpdave11 opened this issue Dec 27, 2018 · 3 comments

Comments

@phpdave11
Copy link

I ran into an issue where phpnsc incorrectly detects a string as being a class.

Code:

<?php

namespace App\Service;

use App\Entity\Order;
use RuntimeException;

class TestService
{
    public function updateOrderStatus(Order $order)
    {
        $class = '\\App\Importer\\' . ucfirst($order->getVendor()->getName());
        if ($order->getStatus() != 'new') {
            throw new RuntimeException("Cannot update order");
        }
        $order->setClass($class);
        $order->setStatus('pending');
    }
}

Here's my phpnsc.json:

{
   "vendor" : "App",
   "folders" : {
       "root"    : "./src/",
       "include" : [""],
       "exclude" : []
   },
   "filetypes" : {
       "include" : [".php"],
       "exclude" : [".config.php"]
   },
   "output" : [{
       "class": "rg\\tools\\phpnsc\\CheckstyleOutput",
       "parameter": "/tmp/phpnsc.xml"
   },{
       "class": "rg\\tools\\phpnsc\\ConsoleOutput",
       "parameter": ""
   }]
}

Result:

$ vendor/rg/phpnsc/phpnsc run phpnsc.json 
Got 62 files
Collect entities...
............................................................ 60/62
.. 62/62
Got 60 defined entities
Check namespaces...
............................................................ 60/62
.. 62/62
Errors found:

/home/dave-barnes/test-project/src/Service/TestService.php (17): Class pending was referenced relatively but not defined
Time: 76 ms, Memory: 8.00MB
@edlerd
Copy link

edlerd commented Feb 15, 2019

As a workaround you can rename the $class variable to $foo. A proper solution is still pending to be released.

@phpdave11
Copy link
Author

Thanks! I will use a different variable name instead of $class to fix this issue.

@smilesrg
Copy link

smilesrg commented Sep 18, 2019

I have the same troubles with the code:

$message = $this->trans('That password reset link is incorrect. Please request a new password reset link.');

I got an error

Class password was referenced relatively but not defined

UPD: it seems it is caused by #1

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

No branches or pull requests

3 participants