mirror of
https://github.com/getgrav/grav.git
synced 2025-02-20 19:56:53 +01:00
Fixed phpstan issues in all code up to level 3
This commit is contained in:
parent
a06520337f
commit
571674a4f5
|
|
@ -7,6 +7,7 @@
|
|||
* Changed `UserInterface::authorize()` to return `null` having the same meaning as `false` if access is denied because of no matching rule
|
||||
* Moved all Flex type classes under `Grav\Common\Flex`
|
||||
* Deprecated `Grav\Common\User\Group` in favor of `$grav['user_groups']`, which contains Flex UserGroup collection
|
||||
* Fixed phpstan issues in all code up to level 3
|
||||
1. [](#improved)
|
||||
* Improved twig `|array` filter to work with iterators and objects with `toArray()` method
|
||||
* Updated Flex `SimpleStorage` code to feature match the other storages
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@
|
|||
"api-16": "vendor/bin/phpdoc-md generate system/src > user/pages/14.api/default.16.md",
|
||||
"api-15": "vendor/bin/phpdoc-md generate system/src > user/pages/14.api/default.md",
|
||||
"post-create-project-cmd": "bin/grav install",
|
||||
"phpstan": "vendor/bin/phpstan analyse -l 2 -c ./tests/phpstan/phpstan.neon system/src --memory-limit=300M",
|
||||
"phpstan": "vendor/bin/phpstan analyse -l 3 -c ./tests/phpstan/phpstan.neon system/src --memory-limit=300M",
|
||||
"phpstan-framework": "vendor/bin/phpstan analyse -l 7 -c ./tests/phpstan/phpstan.neon system/src/Grav/Framework --memory-limit=300M",
|
||||
"test-plugins": "vendor/bin/phpstan analyse -l 0 -c ./tests/phpstan/plugins.neon user/plugins --memory-limit=300M",
|
||||
"test": "vendor/bin/codecept run unit",
|
||||
|
|
|
|||
|
|
@ -55,26 +55,27 @@ class UserCollection extends FlexCollection implements UserCollectionInterface
|
|||
* Find a user by username, email, etc
|
||||
*
|
||||
* @param string $query the query to search for
|
||||
* @param array $fields the fields to search
|
||||
* @param string|string[] $fields the fields to search
|
||||
* @return UserObject
|
||||
*/
|
||||
public function find($query, $fields = ['username', 'email']): UserInterface
|
||||
{
|
||||
// FIXME: $fields is incompatible to parent class -- add support for finding value from multiple properties.
|
||||
foreach ((array)$fields as $field) {
|
||||
if ($field === 'key') {
|
||||
$user = $this->get($query);
|
||||
} elseif ($field === 'storage_key') {
|
||||
$user = $this->withKeyField('storage_key')->get($query);
|
||||
} elseif ($field === 'flex_key') {
|
||||
$user = $this->withKeyField('flex_key')->get($query);
|
||||
} elseif ($field === 'username') {
|
||||
$user = $this->get(mb_strtolower($query));
|
||||
} else {
|
||||
$user = parent::find($query, $field);
|
||||
}
|
||||
if ($user) {
|
||||
return $user;
|
||||
if (is_string($query) && $query !== '') {
|
||||
foreach ((array)$fields as $field) {
|
||||
if ($field === 'key') {
|
||||
$user = $this->get($query);
|
||||
} elseif ($field === 'storage_key') {
|
||||
$user = $this->withKeyField('storage_key')->get($query);
|
||||
} elseif ($field === 'flex_key') {
|
||||
$user = $this->withKeyField('flex_key')->get($query);
|
||||
} elseif ($field === 'username') {
|
||||
$user = $this->get(mb_strtolower($query));
|
||||
} else {
|
||||
$user = parent::find($query, $field);
|
||||
}
|
||||
if ($user) {
|
||||
return $user;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1226,7 +1226,10 @@ class Page implements PageInterface
|
|||
$this->setMedia($var);
|
||||
}
|
||||
|
||||
return $this->getMedia();
|
||||
/** @var Media $media */
|
||||
$media = $this->getMedia();
|
||||
|
||||
return $media;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@ class Filesystem implements FilesystemInterface
|
|||
/** @var bool|null */
|
||||
private $normalize;
|
||||
|
||||
/** @var static */
|
||||
/** @var static|null */
|
||||
protected static $default;
|
||||
|
||||
/** @var static */
|
||||
/** @var static|null */
|
||||
protected static $unsafe;
|
||||
|
||||
/** @var static */
|
||||
/** @var static|null */
|
||||
protected static $safe;
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -15,11 +15,21 @@ use Psr\Http\Message\UploadedFileInterface;
|
|||
|
||||
class FormFlashFile implements UploadedFileInterface, \JsonSerializable
|
||||
{
|
||||
/** @var string */
|
||||
private $field;
|
||||
/** @var bool */
|
||||
private $moved = false;
|
||||
/** @var array */
|
||||
private $upload;
|
||||
/** @var FormFlash */
|
||||
private $flash;
|
||||
|
||||
/**
|
||||
* FormFlashFile constructor.
|
||||
* @param string $field
|
||||
* @param array $upload
|
||||
* @param FormFlash $flash
|
||||
*/
|
||||
public function __construct(string $field, array $upload, FormFlash $flash)
|
||||
{
|
||||
$this->field = $field;
|
||||
|
|
@ -71,7 +81,10 @@ class FormFlashFile implements UploadedFileInterface, \JsonSerializable
|
|||
throw new \RuntimeException(\sprintf('Uploaded file could not be moved to %s', $targetPath));
|
||||
}
|
||||
|
||||
$this->flash->removeFile($this->getClientFilename(), $this->field);
|
||||
$filename = $this->getClientFilename();
|
||||
if ($filename) {
|
||||
$this->flash->removeFile($filename, $this->field);
|
||||
}
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ parameters:
|
|||
bootstrap: tests/phpstan/phpstan-bootstrap.php
|
||||
excludes_analyse:
|
||||
- system/src/Grav/Common/Errors/Resources/layout.html.php
|
||||
inferPrivatePropertyTypeFromConstructor: true
|
||||
reportUnmatchedIgnoredErrors: false
|
||||
universalObjectCratesClasses:
|
||||
- Grav\Common\Config\Config
|
||||
|
|
@ -27,7 +28,6 @@ parameters:
|
|||
- '#Access to an undefined property RocketTheme\\Toolbox\\Event\\Event::#'
|
||||
- '#Access to an undefined property Grav\\Common\\Data\\Blueprint::#'
|
||||
- '#Access to an undefined property Grav\\Common\\Media\\Interfaces\\MediaObjectInterface::#'
|
||||
- '#Access to an undefined property Grav\\Common\\Page\\Interfaces\\PageInterface::#'
|
||||
-
|
||||
message: '#Cannot call method path\(\) on string#'
|
||||
path: 'system/src/Grav/Common/Page/Media.php'
|
||||
|
|
@ -36,9 +36,6 @@ parameters:
|
|||
-
|
||||
message: '#Call to deprecated method writeCacheFile\(\) of class Twig\\Environment#'
|
||||
path: 'system/src/Grav/Common/Twig/WriteCacheFileTrait.php'
|
||||
-
|
||||
message: '#Call to an undefined static method Twig\\Environment::writeCacheFile#'
|
||||
path: 'system/src/Grav/Common/Twig/WriteCacheFileTrait.php'
|
||||
|
||||
# Needed: full coverage (probably with admin plugin...) then redesign constructor
|
||||
-
|
||||
|
|
@ -47,7 +44,6 @@ parameters:
|
|||
|
||||
# PSR-16 Exception interfaces do not extend \Throwable
|
||||
- '#PHPDoc tag \@throws with type Psr\\SimpleCache\\(CacheException|InvalidArgumentException) is not subtype of Throwable#'
|
||||
- '#expects Exception, Psr\\SimpleCache\\InvalidArgumentException&Throwable given#'
|
||||
|
||||
# Needed: psr-17 (http-factories) support (through decorator or further investigations)
|
||||
-
|
||||
|
|
@ -57,11 +53,6 @@ parameters:
|
|||
# Medium __call() methods
|
||||
- '#Call to an undefined method Grav\\Common\\Page\\Medium\\(\w*)Medium::#'
|
||||
|
||||
# Filesystem::getInstance()
|
||||
-
|
||||
message: '#Strict comparison using === between null and static#'
|
||||
path: 'system/src/Grav/Framework/Filesystem/Filesystem.php'
|
||||
|
||||
# These errors are about plugins (need to find a better solution)
|
||||
-
|
||||
message: '#Call to static method sendEmail\(\) on an unknown class Grav\\Plugin\\Email\\Utils#'
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user