soberwp/models

Problem with phan and phpmd

jkwasniak opened this issue · 5 comments

Currently, I get an error message when calling PHAN and PHPMD

PHAN

/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run code:analysis:phan --scripts-prepend-node-path=auto

> sage@9.0.0-beta.4 code:analysis:phan /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc
> vendor/bin/phan

Automatically disabling xdebug, it's unnecessary unless you are debugging or developing phan itself, and makes phan slower.
To run Phan with xdebug, set the environment variable PHAN_ALLOW_XDEBUG to 1.
To disable this warning, set the environment variable PHAN_DISABLE_XDEBUG_WARN to 1.
To include function signatures of xdebug, see .phan/internal_stubs/xdebug.xdebug.phan_php

PHP Fatal error:  Uncaught Error: Call to undefined function Sober\Models\add_action() in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php:10
Stack trace:
Fatal error: Uncaught Error: Call to undefined function Sober\Models\add_action() in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php:10
#0 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php(66): require()
Stack trace:
#0 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php(66): require()
#1 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php(56): composerRequire66069733c45247774b65bd23b9df75d7('90abbbd1b4ec36a...', '/Users/xxx/D...')
#2 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/autoload.php(7): ComposerAutoloaderInit66069733c45247774b65bd23b9df75d7::getLoader()
#1 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php(56): composerRequire66069733c45247774b65bd23b9df75d7('90abbbd1b4ec36a...', '/Users/xxx/D...')
#3 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phan/phan/src/codebase.php(14): require_once('/Users/xxx/D...')
#2 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/autoload.php(7): ComposerAutoloaderInit66069733c45247774b65bd23b9df75d7::getLoader()
#4 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phan/phan/src/phan.php(14): require_once('/Users/xxx/D...')
#3 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phan/phan/src/codebase.php(14): require_once('/Users/xxx/D...')
#5 /Users/xxx/Documents/Developer/PHP in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php on line 10
#4 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phan/phan/src/phan.php(14): require_once('/Users/xxx/D...')
#5 /Users/xxx/Documents/Developer/PHP in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php on line 10
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! sage@9.0.0-beta.4 code:analysis:phan: `vendor/bin/phan`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the sage@9.0.0-beta.4 code:analysis:phan script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2018-01-15T07_46_32_758Z-debug.log

Process finished with exit code 255

PHPMD

/usr/local/bin/node /usr/local/lib/node_modules/npm/bin/npm-cli.js run code:analysis:phpmd --scripts-prepend-node-path=auto

> sage@9.0.0-beta.4 code:analysis:phpmd /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc
> vendor/bin/phpmd app/controllers/,src/,tests/ text phpmd.xml


Fatal error: Uncaught Error: Call to undefined function Sober\Models\add_action() in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php on line 10

Error: Call to undefined function Sober\Models\add_action() in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php on line 10

Call Stack:
    0.0004     439144   1. {main}() /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phpmd/phpmd/src/bin/phpmd:0
    0.0006     440400   2. require_once('/Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/autoload.php') /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phpmd/phpmd/src/bin/phpmd:8
    0.0008     455824   3. ComposerAutoloaderInit66069733c45247774b65bd23b9df75d7::getLoader() /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/autoload.php:7
    0.0038     920408   4. composerRequire66069733c45247774b65bd23b9df75d7() /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php:56
    0.0039     922136   5. require('/Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-agbedachungen/vendor/soberwp/models/models.php') /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php:66

PHP Fatal error:  Uncaught Error: Call to undefined function Sober\Models\add_action() in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php:10
Stack trace:
#0 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php(66): require()
#1 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/composer/autoload_real.php(56): composerRequire66069733c45247774b65bd23b9df75d7('90abbbd1b4ec36a...', '/Users/janusz/D...')
#2 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/autoload.php(7): ComposerAutoloaderInit66069733c45247774b65bd23b9df75d7::getLoader()
#3 /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/phpmd/phpmd/src/bin/phpmd(8): require_once('/Users/janusz/D...')
#4 {main}
  thrown in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/models.php on line 10
npm ERR! code ELIFECYCLE
npm ERR! errno 255
npm ERR! sage@9.0.0-beta.4 code:analysis:phpmd: `vendor/bin/phpmd app/controllers/,src/,tests/ text phpmd.xml`
npm ERR! Exit status 255
npm ERR! 
npm ERR! Failed at the sage@9.0.0-beta.4 code:analysis:phpmd script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/xxx/.npm/_logs/2018-01-15T07_46_10_397Z-debug.log

Process finished with exit code 255

Following change in model.php brings the remedy (similar to sober controller)

<?php

namespace Sober\Models;

use Sober\Models\Loader;

function loader()
{
    new Loader();
}

/**
 * Hooks
 */
if (function_exists('add_action')) {
    add_action('init', __NAMESPACE__ . '\loader');
}

Can you just look at this?

Sure, I will add!

Thanks! Do you know when you implement that?

@jkwasniak I will add and tag a new release this afternoon

Thanks! After update (johnbillion/extended-cpts (4.2.0) was also changed) i get following error

> sage@9.0.0-beta.4 code:analysis:phan /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc
> vendor/bin/phan

Automatically disabling xdebug, it's unnecessary unless you are debugging or developing phan itself, and makes phan slower.
To run Phan with xdebug, set the environment variable PHAN_ALLOW_XDEBUG to 1.
To disable this warning, set the environment variable PHAN_DISABLE_XDEBUG_WARN to 1.
To include function signatures of xdebug, see .phan/internal_stubs/xdebug.xdebug.phan_php

PHP Fatal error:  Cannot redeclare register_extended_post_type() (previously declared in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/johnbillion/extended-cpts/functions.php:59) in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/dist/johnbillion/extended-cpts/functions.php on line 69
Fatal error: Cannot redeclare register_extended_post_type() (previously declared in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/johnbillion/extended-cpts/functions.php:59) in /Users/xxx/Documents/Developer/PHP/wordpress/privat/wp-abc/vendor/soberwp/models/dist/johnbillion/extended-cpts/functions.php on line 69

Can you just look at this?

Yeah, extended-cpts was causing issues. I've removed for now, so should be using WordPress default functions again. You can try get v1.0.6 again and should be working.