PhpDoc生成警告

问题描述 投票:-1回答:2

以下文档中生成的警告消息是在文档内的所有方法中看到的消息。

警告:count():参数必须是一个数组或在C98上实现Countable的对象:在线1198上的C:\ php72 \ pear \ phpDocumentor \ vendor \ twig \ twig \ lib \ Twig \ Extension \ Core.php警告:count() :参数必须是一个数组或一个对象,它在第1198行的C:\ php72 \ pear \ phpDocumentor \ vendor \ twig \ twig \ lib \ Twig \ Extension \ Core.php中实现Countable enter image description here

warnings messages phpdoc
2个回答
0
投票

好的找到了解决方案。

见链接https://area51.phpbb.com/phpBB/viewtopic.php?t=52691

更改了core.php文件中的函数

    /**
 * Returns the length of a variable.
 *
 * @param Twig_Environment $env
 * @param mixed            $thing A variable
 *
 * @return int The length of the value
 */
function twig_length_filter(Twig_Environment $env, $thing)
{
    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());
    }

    return count($thing);
}

跟随

/**
 * Returns the length of a variable.
 *
 * @param Twig_Environment $env
 * @param mixed            $thing A variable
 *
 * @return int The length of the value
 */
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;
}

0
投票

我一直在努力纠正这个错误,所以我希望在这里分享完整的解决方案:要更改的内容以及如何编辑phar文件:

将此脚本复制到phar文件夹中的文件中,并使用php命令行运行它,并在代码中指定选项:

<?php
//to be run with php -d phar.readonly=Off -f thisFileName 
if (ini_get('phar.readonly')==1){
    die("\n\nThis script must be run with option -d phar.readonly=Off so that it can write the .phar file\n\n"); 
}

//the file you want to change
$file = 'vendor/twig/twig/lib/Twig/Extension/Core.php';

//the function in the file you want to change
$oldFunction = '#function twig_length_filter[^{]*[^}]*}#'; //assuming it's still the actual one line function, regex might need updates in the furure

//the replacement function
$newFunction = <<<'funct'
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;
    }
funct;

//access the phar
$p = new Phar('phpDocumentor.phar', FilesystemIterator::CURRENT_AS_FILEINFO | FilesystemIterator::KEY_AS_FILENAME);
//extract the file
$p->extractTo('./', $file, true);

//return here if you want to check the file first
//return;

//change the function 
file_put_contents($file,
    $newFile = preg_replace(
            $oldFunction, 
            $newFunction, 
            file_get_contents($file)
        )
    );

//update the file
$p[$file] = $file;

//done
echo 'Done. Don\'t forget to delete the "vendor" folder extracted from the phar !';
© www.soinside.com 2019 - 2024. All rights reserved.