mirror of
https://github.com/getgrav/grav.git
synced 2025-10-26 07:56:07 +01:00
Fixed phpstan issues (All level 2, Framework level 5)
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
|
||||
1. [](#new)
|
||||
* Added support to get image size for SVG vector images [#3533](https://github.com/getgrav/grav/pull/3533)
|
||||
* Fixed phpstan issues (All level 2, Framework level 5)
|
||||
2. [](#bugfix)
|
||||
* Fixed `'mbstring' extension is not loaded` error, use Polyfill instead [#3504](https://github.com/getgrav/grav/pull/3504)
|
||||
|
||||
|
||||
@@ -115,8 +115,8 @@
|
||||
"scripts": {
|
||||
"api-17": "vendor/bin/phpdoc-md generate system/src > user/pages/14.api/default.17.md",
|
||||
"post-create-project-cmd": "bin/grav install",
|
||||
"phpstan": "vendor/bin/phpstan analyse -l 1 -c ./tests/phpstan/phpstan.neon --memory-limit=720M system/src",
|
||||
"phpstan-framework": "vendor/bin/phpstan analyse -l 4 -c ./tests/phpstan/phpstan.neon --memory-limit=480M system/src/Grav/Framework system/src/Grav/Events system/src/Grav/Installer",
|
||||
"phpstan": "vendor/bin/phpstan analyse -l 2 -c ./tests/phpstan/phpstan.neon --memory-limit=720M system/src",
|
||||
"phpstan-framework": "vendor/bin/phpstan analyse -l 5 -c ./tests/phpstan/phpstan.neon --memory-limit=480M system/src/Grav/Framework system/src/Grav/Events system/src/Grav/Installer",
|
||||
"phpstan-plugins": "vendor/bin/phpstan analyse -l 1 -c ./tests/phpstan/plugins.neon --memory-limit=400M user/plugins",
|
||||
"test": "vendor/bin/codecept run unit",
|
||||
"test-windows": "vendor\\bin\\codecept run unit"
|
||||
|
||||
24
composer.lock
generated
24
composer.lock
generated
@@ -4748,16 +4748,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-code-coverage",
|
||||
"version": "9.2.10",
|
||||
"version": "9.2.11",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/php-code-coverage.git",
|
||||
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687"
|
||||
"reference": "665a1ac0a763c51afc30d6d130dac0813092b17f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/d5850aaf931743067f4bfc1ae4cbd06468400687",
|
||||
"reference": "d5850aaf931743067f4bfc1ae4cbd06468400687",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/php-code-coverage/zipball/665a1ac0a763c51afc30d6d130dac0813092b17f",
|
||||
"reference": "665a1ac0a763c51afc30d6d130dac0813092b17f",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -4813,7 +4813,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/php-code-coverage/issues",
|
||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.10"
|
||||
"source": "https://github.com/sebastianbergmann/php-code-coverage/tree/9.2.11"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -4821,7 +4821,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2021-12-05T09:12:13+00:00"
|
||||
"time": "2022-02-18T12:46:09+00:00"
|
||||
},
|
||||
{
|
||||
"name": "phpunit/php-file-iterator",
|
||||
@@ -5066,16 +5066,16 @@
|
||||
},
|
||||
{
|
||||
"name": "phpunit/phpunit",
|
||||
"version": "9.5.13",
|
||||
"version": "9.5.14",
|
||||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/sebastianbergmann/phpunit.git",
|
||||
"reference": "597cb647654ede35e43b137926dfdfef0fb11743"
|
||||
"reference": "1883687169c017d6ae37c58883ca3994cfc34189"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/597cb647654ede35e43b137926dfdfef0fb11743",
|
||||
"reference": "597cb647654ede35e43b137926dfdfef0fb11743",
|
||||
"url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/1883687169c017d6ae37c58883ca3994cfc34189",
|
||||
"reference": "1883687169c017d6ae37c58883ca3994cfc34189",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
@@ -5153,7 +5153,7 @@
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/phpunit/issues",
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.13"
|
||||
"source": "https://github.com/sebastianbergmann/phpunit/tree/9.5.14"
|
||||
},
|
||||
"funding": [
|
||||
{
|
||||
@@ -5165,7 +5165,7 @@
|
||||
"type": "github"
|
||||
}
|
||||
],
|
||||
"time": "2022-01-24T07:33:35+00:00"
|
||||
"time": "2022-02-18T12:54:07+00:00"
|
||||
},
|
||||
{
|
||||
"name": "psr/http-client",
|
||||
|
||||
@@ -525,8 +525,8 @@ class Assets extends PropertyObject
|
||||
/**
|
||||
* Build the Javascript Modules tags
|
||||
*
|
||||
* @param $group
|
||||
* @param $attributes
|
||||
* @param string $group
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
public function jsModule($group = 'head', $attributes = [])
|
||||
@@ -534,6 +534,11 @@ class Assets extends PropertyObject
|
||||
return $this->render(self::JS_MODULE, $group, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $group
|
||||
* @param array $attributes
|
||||
* @return string
|
||||
*/
|
||||
public function all($group = 'head', $attributes = [])
|
||||
{
|
||||
$output = $this->css($group, $attributes, false);
|
||||
@@ -543,11 +548,19 @@ class Assets extends PropertyObject
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $type
|
||||
* @return bool
|
||||
*/
|
||||
protected function isValidType($type)
|
||||
{
|
||||
return in_array($type, [self::CSS_TYPE, self::JS_TYPE, self::JS_MODULE_TYPE]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param class-string $type
|
||||
* @return string
|
||||
*/
|
||||
protected function getBaseType($type)
|
||||
{
|
||||
switch ($type) {
|
||||
|
||||
@@ -55,7 +55,7 @@ class BlockAssets
|
||||
|
||||
/**
|
||||
* @param Assets $assets
|
||||
* @param array $groups
|
||||
* @param array $list
|
||||
* @return void
|
||||
*/
|
||||
protected static function registerFrameworks(Assets $assets, array $list): void
|
||||
|
||||
@@ -606,8 +606,10 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
|
||||
}
|
||||
}
|
||||
|
||||
/** @var PageCollection|PageIndex $children */
|
||||
$children = $page->children();
|
||||
/** @var PageIndex $children */
|
||||
$children = $page->children()->getIndex();
|
||||
$children = $children->getIndex();
|
||||
$selectedChildren = $children->filterBy($filters, true);
|
||||
|
||||
/** @var Header $header */
|
||||
@@ -686,6 +688,8 @@ class PageIndex extends FlexPageIndex implements PageCollectionInterface
|
||||
$extras = array_filter($extras, static function ($v) {
|
||||
return $v !== null;
|
||||
});
|
||||
|
||||
/** @var PageIndex $tmp */
|
||||
$tmp = $child->children()->getIndex();
|
||||
$child_count = $tmp->count();
|
||||
$count = $filters ? $tmp->filterBy($filters, true)->count() : null;
|
||||
|
||||
@@ -625,7 +625,14 @@ class PageObject extends FlexPageObject
|
||||
|
||||
// If current filter does not match, we still may have match as a parent.
|
||||
if ($matches === false) {
|
||||
return $recursive && $this->children()->getIndex()->filterBy($filters, true)->count() > 0;
|
||||
if (!$recursive) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/** @var PageIndex $index */
|
||||
$index = $this->children()->getIndex();
|
||||
|
||||
return $index->filterBy($filters, true)->count() > 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,8 @@ use Grav\Common\Data\Data;
|
||||
* Class implements media object interface.
|
||||
*
|
||||
* @property string $type
|
||||
* @property string $filename
|
||||
* @property string $filepath
|
||||
*/
|
||||
interface MediaObjectInterface extends \Grav\Framework\Media\Interfaces\MediaObjectInterface, ArrayAccess
|
||||
{
|
||||
|
||||
@@ -53,10 +53,10 @@ class VectorImageMedium extends StaticImageMedium
|
||||
}
|
||||
|
||||
// Get the size from svg image.
|
||||
if ($attr->width > 0 && $attr->height > 0) {
|
||||
$width = $attr->width;
|
||||
$height = $attr->height;
|
||||
} elseif ($attr->viewBox && \count($size = explode(' ', $attr->viewBox)) === 4) {
|
||||
if ($attr->width && $attr->height) {
|
||||
$width = (string)$attr->width;
|
||||
$height = (string)$attr->height;
|
||||
} elseif ($attr->viewBox && \count($size = explode(' ', (string)$attr->viewBox)) === 4) {
|
||||
[,$width,$height,] = $size;
|
||||
}
|
||||
|
||||
|
||||
@@ -736,7 +736,13 @@ class Pages
|
||||
break;
|
||||
case 'siblings':
|
||||
$parent = $page->parent();
|
||||
$collection = $parent ? $parent->children()->remove($page->path()) : new Collection();
|
||||
if ($parent) {
|
||||
/** @var Collection $collection */
|
||||
$collection = $parent->children();
|
||||
$collection = $collection->remove($page->path());
|
||||
} else {
|
||||
$collection = new Collection();
|
||||
}
|
||||
break;
|
||||
case 'descendants':
|
||||
$collection = $this->all($page)->remove($page->path())->pages();
|
||||
@@ -1041,9 +1047,14 @@ class Pages
|
||||
$this->grav->redirectLangSafe($page->redirect());
|
||||
}
|
||||
|
||||
if (!$routable && ($child = $page->children()->visible()->routable()->published()->first()) !== null) {
|
||||
// Redirect to the first visible child as current page isn't routable.
|
||||
$this->grav->redirectLangSafe($child->route());
|
||||
if (!$routable) {
|
||||
/** @var Collection $children */
|
||||
$children = $page->children()->visible()->routable()->published();
|
||||
$child = $children->first();
|
||||
if ($child !== null) {
|
||||
// Redirect to the first visible child as current page isn't routable.
|
||||
$this->grav->redirectLangSafe($child->route());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,8 @@ namespace Grav\Common\Twig;
|
||||
|
||||
use Twig\Environment;
|
||||
use Twig\Error\LoaderError;
|
||||
use Twig\Loader\ExistsLoaderInterface;
|
||||
use Twig\Loader\LoaderInterface;
|
||||
use Twig\Template;
|
||||
use Twig\TemplateWrapper;
|
||||
|
||||
@@ -41,8 +43,12 @@ class TwigEnvironment extends Environment
|
||||
}
|
||||
|
||||
// Optimization: Avoid throwing an exception when it would be ignored anyway.
|
||||
if (1 !== $count && !$this->getLoader()->exists($name)) {
|
||||
continue;
|
||||
if (1 !== $count) {
|
||||
/** @var LoaderInterface|ExistsLoaderInterface $loader */
|
||||
$loader = $this->getLoader();
|
||||
if (!$loader->exists($name)) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Throws LoaderError: Unable to find template "%s".
|
||||
|
||||
Reference in New Issue
Block a user