Skip to content

Commit

Permalink
Merge pull request #3 from meritoo/chore/phpstan
Browse files Browse the repository at this point in the history
Fix PHPStan errors
  • Loading branch information
meritoo authored Nov 16, 2024
2 parents f4fd74f + f1bed40 commit 9bfcc1f
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Common & useful classes, resources, extensions. Based on Symfony framework.
2. Pluralization in
translations [using the ICU MessageFormat](https://symfony.com/doc/current/reference/formats/message_format.html#pluralization)
3. Update the `meritoo/common-library` package to `^1.3`
4. Fix PHPStan errors

# 0.3.1

Expand Down
2 changes: 1 addition & 1 deletion phpstan.neon.dist → phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ parameters:
paths:
- src
- tests
excludes_analyse:
excludePaths:
- %rootDir%/../../../tests/Resources/var/*
29 changes: 20 additions & 9 deletions src/Bundle/Descriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,20 @@ class Descriptor
/**
* Class constructor
*
* @param string $name (optional) Name of bundle
* @param string $configurationRootName (optional) Name of configuration root node of bundle
* @param string $rootNamespace (optional) Root namespace of bundle
* @param string $path (optional) Physical path of bundle
* @param string $name (optional) Name of bundle
* @param string $configurationRootName (optional) Name of configuration root node of bundle
* @param string $rootNamespace (optional) Root namespace of bundle
* @param string $path (optional) Physical path of bundle
* @param null|Descriptor $parentBundleDescriptor (optional) Descriptor of the parent bundle
* @param null|Descriptor $childBundleDescriptor (optional) Descriptor of the child bundle
* @param null|Descriptor $childBundleDescriptor (optional) Descriptor of the child bundle
*/
public function __construct(
string $name = '',
string $configurationRootName = '',
string $rootNamespace = '',
string $path = '',
?Descriptor $parentBundleDescriptor = null,
?Descriptor $childBundleDescriptor = null
?Descriptor $childBundleDescriptor = null,
) {
$this->name = $name;
$this->configurationRootName = $configurationRootName;
Expand All @@ -119,6 +119,7 @@ public function __construct(
* Adds names of files with data fixtures from bundle
*
* @param array $fixturesPaths Names of files with data fixtures
*
* @return Descriptor
*/
public function addDataFixtures(array $fixturesPaths): Descriptor
Expand All @@ -136,6 +137,7 @@ public function addDataFixtures(array $fixturesPaths): Descriptor
* Creates and returns descriptor from given data
*
* @param array $data Data of descriptor
*
* @return Descriptor
*/
public static function fromArray(array $data): Descriptor
Expand Down Expand Up @@ -175,20 +177,21 @@ public static function fromArray(array $data): Descriptor
$childBundleDescriptor = static::fromArray($childData);
}

return new static(
return new self(
$name,
$configurationRootName,
$rootNamespace,
$path,
$parentBundleDescriptor,
$childBundleDescriptor
$childBundleDescriptor,
);
}

/**
* Creates and returns descriptor of given bundle
*
* @param Bundle $bundle The bundle
*
* @return Descriptor
*/
public static function fromBundle(Bundle $bundle): Descriptor
Expand All @@ -201,7 +204,7 @@ public static function fromBundle(Bundle $bundle): Descriptor
// Default values, not provided by bundle directly
$configurationRootName = '';

return new static($name, $configurationRootName, $rootNamespace, $path);
return new self($name, $configurationRootName, $rootNamespace, $path);
}

/**
Expand All @@ -218,6 +221,7 @@ public function getChildBundleDescriptor(): ?Descriptor
* Sets descriptor of the child bundle
*
* @param Descriptor|null $childBundleDescriptor (optional) The child's descriptor
*
* @return Descriptor
*/
public function setChildBundleDescriptor(?Descriptor $childBundleDescriptor): Descriptor
Expand All @@ -241,6 +245,7 @@ public function getConfigurationRootName(): string
* Sets name of configuration root node of bundle
*
* @param string $configurationRootName The name
*
* @return Descriptor
*/
public function setConfigurationRootName(string $configurationRootName): Descriptor
Expand Down Expand Up @@ -293,6 +298,7 @@ public function getName(): string
* Sets name of bundle
*
* @param string $name The name
*
* @return Descriptor
*/
public function setName(string $name): Descriptor
Expand All @@ -316,6 +322,7 @@ public function getParentBundleDescriptor(): ?Descriptor
* Sets descriptor of the parent bundle
*
* @param Descriptor|null $parentBundleDescriptor (optional) The parent's descriptor
*
* @return Descriptor
*/
public function setParentBundleDescriptor(?Descriptor $parentBundleDescriptor): Descriptor
Expand All @@ -339,6 +346,7 @@ public function getPath(): string
* Sets physical path of bundle
*
* @param string $path The path
*
* @return Descriptor
*/
public function setPath(string $path): Descriptor
Expand All @@ -362,6 +370,7 @@ public function getRootNamespace(): string
* Sets root namespace of bundle
*
* @param string $rootNamespace The root namespace
*
* @return Descriptor
*/
public function setRootNamespace(string $rootNamespace): Descriptor
Expand Down Expand Up @@ -392,6 +401,7 @@ public function getShortName(): string
* Returns information if given file belongs to bundle
*
* @param string $filePath Path of file to verify
*
* @return bool
*/
public function hasFile(string $filePath): bool
Expand All @@ -404,6 +414,7 @@ public function hasFile(string $filePath): bool
*
* @param bool $withParentAndChild (optional) If is set to true, includes descriptor of the parent and child
* bundle (default behaviour). Otherwise - not.
*
* @return array
*/
public function toArray(bool $withParentAndChild = true): array
Expand Down
5 changes: 4 additions & 1 deletion src/Bundle/Descriptors.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,12 @@ class Descriptors extends BaseCollection
* Returns the descriptors created from given data
*
* @param array $data Data of descriptors
*
* @return Descriptors
*/
public static function fromArray(array $data): Descriptors
{
$result = new static();
$result = new self();

if (!empty($data)) {
$descriptors = [];
Expand All @@ -48,6 +49,7 @@ public static function fromArray(array $data): Descriptors
* Returns descriptor of bundle that contains given class
*
* @param string $classNamespace Namespace of class for which descriptor of bundle should be returned
*
* @return null|Descriptor
*/
public function getDescriptor(string $classNamespace): ?Descriptor
Expand Down Expand Up @@ -81,6 +83,7 @@ public function getDescriptor(string $classNamespace): ?Descriptor
* Returns descriptor of bundle with given name
*
* @param string $bundleName Name of bundle who descriptor should be returned
*
* @return null|Descriptor
*/
public function getDescriptorByName(string $bundleName): ?Descriptor
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ public static function create(): CannotRedirectToEmptyRefererUrlException

$message = sprintf($template, RequestServiceInterface::class, 'storeRefererUrl');

return new static($message);
return new self($message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class EmptyVersionFilePathException extends RuntimeException
*/
public static function create(): EmptyVersionFilePathException
{
return new static('Path of a file, who contains version of the application, is empty. Is there everything ok?');
return new self('Path of a file, who contains version of the application, is empty. Is there everything ok?');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ class UnreadableVersionFileException extends RuntimeException
* Creates exception
*
* @param string $filePath Path of a file who contains version of the application
*
* @return UnreadableVersionFileException
*/
public static function create(string $filePath): UnreadableVersionFileException
{
$template = 'File %s, who contains version of the application, is not readable. Does the file exist?';
$message = sprintf($template, $filePath);

return new static($message);
return new self($message);
}
}

0 comments on commit 9bfcc1f

Please sign in to comment.