beside that it's time to support nullable return types of PHP 7.1 with PHP 7.2 you have tons of new runtime warnings:
Warning: count(): Parameter must be an array or an object that implements Countable in phar:///mnt/data/www/thelounge.net/contentlounge/updateservice/phpDocumentor.phar/src/phpDocumentor/Plugin/Core/Descriptor/Validator/Constraints/Functions/IsArgumentInDocBlockValidator.php on line 33
[20-Nov-2017 15:16:28 Europe/Vienna] PHP Warning: count(): Parameter must be an array or an object that implements Countable in phar:///mnt/data/www/thelounge.net/contentlounge/updateservice/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
I fixed the problem by checking whether $thing implements the Countable interface. Changed the function to:
twig_length_filter (using the @ fixed)
function twig_length_filter(Twig_Environment $env, $thing)
{
return is_scalar($thing) ? mb_strlen($thing, $env->getCharset()) : ($thing instanceof Countable ? count($thing):0);
}
I can confirm the behaviour;
Warning: count(): Parameter must be an array or an object that implements Countable in phar://C:/wip/test-project/vendor/phpdocumentor/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293 Warning: count(): Parameter must be an array or an object that implements Countable in phar://C:/wip/test-project/vendor/phpdocumentor/phpDocumentor.phar/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1293
Really affects the documentation.
To add to what @imelgrat said, you may want to change the file
IsArgumentInDocBlockValidator.php
You should change line 33 from
if ($value instanceof ValidationValueObject && count($value->argument) > 0)
to
if ($value instanceof ValidationValueObject && $value instanceof Countable && count($value->argument) > 0)
If you are using the PHAR version, you will have to extract it to a zip, then apply the fix
frankly why can't there be a current devel-version as phar to download since even PHP 7.1.x syntax is not supported currently and so half of the documentations are not generated at all when the codebase is using nullable return types?
Please try the alpha version of v3. It is still work in progress but it will help you out.
WHERE can i download a phar of v3
don't work at all meaning generates empty docs
first it don't understand things like "--filename="/www/phpincludes/global.php" any longer
Warning: file_get_contents(/www/phpincludes/global.php): failed to open stream: No such file or directory in phar:///mnt/data/www/thelounge.net/contentlounge/updateservice/phpDocumentor.phar/vendor/phpdocumentor/reflection/src/phpDocumentor/Reflection/File/LocalFile.php on line 44
second the following call also leads in empty docs
/usr/bin/time -f "%E" php -d "extension=tokenizer.so" "$CMS_UPDATE_SERVICE_LOCATION/phpDocumentor.phar" run --force --progressbar --cache-folder="/tmp" --encoding="ISO-8859-1" --directory="$CMS_UPDATE_SERVICE_LOCATION/package" --filename="/www/phpincludes/newsletter.php" --ignore="modules/blog/tagcloud.php" --target="$CMS_UPDATE_SERVICE_LOCATION/documentation/code-referenzen/contentlounge" --title="ContentLounge - Technische Referenz" --defaultpackagename="ContentLounge" --template="clean"
ContentLounge - Technische Referenz
Collecting files .. OK
Initializing parser .. OK
Parsing files
1/1 [============================] 100%
Storing cache in "/tmp" .. OK
Load cache .. 0.001s
Preparing template "clean" .. 0.003s
Preparing 17 transformations .. 0.000s
Build "elements" index .. 0.000s
Replace textual FQCNs with object aliases .. 0.000s
Resolve @link and @see tags in descriptions .. 0.000s
Enriches inline example tags with their sources .. 0.000s
Build "packages" index .. 0.000s
Adding Parents to child interfaces .. 0.000s
Collect all markers embedded in tags .. 0.000s
Build "namespaces" index and add namespaces to "elements" .. 0.000s
Adding Parents to child classes .. 0.000s
17/17 [============================] 100% 0.055s ..
Analyze results and write report to log .. 0.000s
0:00.37
I dont know , i did correct or not in php7.2
changed the function
function twig_length_filter(Twig_Environment $env, $thing)
{
if (null === $thing) {
return 0;
}
if (is_scalar($thing)) {
return mb_strlen($thing, $env->getCharset());
}
if (is_object($thing) && method_exists($thing, '__toString') && !$thing instanceof \Countable) {
return mb_strlen((string) $thing, $env->getCharset());
}
if ($thing instanceof \Countable || is_array($thing)) {
return count($thing);
}
return 1;
}
get rid of warning but shows some message while doc generated in command prompt :
Unable to find the dot command of the GraphViz package. Is GraphViz correctly installed and present in your path?
@wilroydmello, the problem is not related to the twig_length_filter function itself but to not having GraphViz installed (or properly configured) on your machine. If you're running your site on Windows, the steps to resolve this error are:
If you're running a Linux server, you need to run the following command to install and configure GrapViz
After that, you should be able to run phpdoc using Graphviz
Applied both patches. Now it works OK on PHP 7.2 (phar file in zip archive)
phpdoc(7.2).phar.zip
Please try the alpha version of v3. It is still work in progress but it will help you out.
I just want to give alpha.2 a try but I have no luck at all and I can't find any "breaking changes" document. It's so annoying - phpDocumentor.phar run -c phpdoc.xml... finished without errors but ignores the configuration file...
@LewisJohnson this is quiet useless patch:
if ($value instanceof ValidationValueObject && $value instanceof Countable && count($value->argument) > 0)
If $value is countable it doesn't mean $value->argument is also countable. A better solution:
$count = is_array($value->argument) || $value->argument instanceof \Countable ? count($value->argument) : 0;
if ($value instanceof ValidationValueObject && $count > 0)
Applied both patches. Now it works OK on PHP 7.2 (phar file in zip archive)
phpdoc(7.2).phar.zip
Thank you very much, resolved here.
I use PHP 7.2 and with that phar generated by you, it has disappeared.
I saw this same problem on a 4 day open issue, it would be nice to update officially with the fix, thanks again for the help.
I just should warn themes do not work in phar due to internal unfixable PHPDoc2 bug so if you want to use them you should use unpacked version.
php "path\to\phpdoc\bin\phpdoc" --config path\to\config\config.xml
https://github.com/phpDocumentor/phpDocumentor2/issues/713
If you have ideas how to patch this just let me know
Thanks for the info.
The Dockerfile uses php:7 on Docker, which won't use 7.3 and is causing this issue occur on all current and develop releases on Docker hub.
A better solution:
$count = is_array($value->argument) || $value->argument instanceof \Countable ? count($value->argument) : 0; if ($value instanceof ValidationValueObject && $count > 0)
Actually, I think $value->argument should only be tested once $value instanceof ValidationValueObject is satisfied. And since $value->argument uses a magic __get it would be more efficient to store the result. Thus:
if ($value instanceof ValidationValueObject) {
$argument = $value->argument;
if ((\is_array($argument) || $argument instanceof \Countable) && \count($argument) > 0) {
/* @var $params \phpDocumentor\Descriptor\Collection */
// ...
}
}
This issue is about the Validators in phpDocumentor 2.9. That system was removed in 3.0 and is not scheduled to be reintroduced soon. phpDocumentor 2.9 is also not scheduled to include support for PHP 7 or higher.
As such, any issues in the validator mechanism should be resolved in the 2.9 branch and is not included in our work on 3.0.
To resolve this item soon, assistance is needed from the community in the form of a PR on the 2.9 branch.
This has actually been fixed in the 2.9 branch by https://github.com/phpDocumentor/phpDocumentor/commit/3c10cdf81af3e7901097705c705b3d4fb5b6e43f (see #1808) but there has not been a 2.9.x release since then.
Hi @JakeQZ, I'm glad that you are paying more attention than I was :sweat_smile: We'll need to do a release then! At this moment I am wrapped in another effort; after that is finished I'll check out that release (2.9 did not have a fully automated release cycle yet)
Release is complete: https://github.com/phpDocumentor/phpDocumentor/releases/tag/v2.9.1
The phar is now downloadable from that location. I still need to build and release the PEAR archive but I am running into a couple issues there
I downloaded the phar file from https://github.com/phpDocumentor/phpDocumentor/releases/tag/v2.9.1 and this gave me the exact same error, just this time it was twig acting up.
The twig_length_filter() method in twig/twig/lib/Twig/Extension/Core.php ends up returning a count on $thing, if everything else fails. I modified the method to only return a count on $thing, if it is a Countable object (otherwise just return 0), and that made phpDoc finish without further errors.
I have a suspicion, that it relates to how phpDoc uses twig, rather than a twig bug, but i only made it go away, by modifying the twig file, so no PR, unfortunately.
If you are using phpdocumentor in a modern project you might want to check our latest beta release. But please don't reply on closed issues. They are not traceable.
Most helpful comment
Applied both patches. Now it works OK on PHP 7.2 (phar file in zip archive)
phpdoc(7.2).phar.zip