Skip to content

Commit

Permalink
Code: fix phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
f3l1x committed Dec 1, 2023
1 parent 6a378f1 commit 1c37255
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 16 deletions.
1 change: 0 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ parameters:
- '#^Only booleans are allowed in#'

# Ignore bad php internal functions behavior
- '#^Parameter \#1 \$haystack of static method Nette\\Utils\\Strings\:\:contains\(\) expects string, string\|false given\.$#'
- message: '#^Method Apitte\\Core\\Annotation\\Controller\\OpenApi\:\:purifyDocblock\(\) should return string but returns string\|null\.$#'
path: %currentWorkingDirectory%/src/Core/Annotation/Controller/OpenApi.php

Expand Down
5 changes: 2 additions & 3 deletions src/Core/Mapping/Validator/BasicValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Apitte\Core\Exception\Api\ValidationException;
use Apitte\Core\Mapping\Request\BasicEntity;
use Nette\Utils\Strings;
use ReflectionObject;

class BasicValidator implements IEntityValidator
Expand Down Expand Up @@ -46,9 +45,9 @@ protected function validateProperties(BasicEntity $entity): array

foreach (array_keys($properties) as $propertyName) {
$propertyRf = $rf->getProperty($propertyName);
$doc = $propertyRf->getDocComment();
$doc = (string) $propertyRf->getDocComment();

if (Strings::contains($doc, '@required') && $entity->{$propertyName} === null) {
if (str_contains($doc, '@required') && $entity->{$propertyName} === null) {
$violations[$propertyName][] = 'This value should not be null.';
}
}
Expand Down
1 change: 0 additions & 1 deletion src/Core/Mapping/Validator/SymfonyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function setConstraintValidatorFactory(ConstraintValidatorFactoryInterfac
*/
public function validate(object $entity): void
{
// @phpstan-ignore-next-line
$validatorBuilder = Validation::createValidatorBuilder();
$validatorBuilder->enableAttributeMapping();

Expand Down
4 changes: 1 addition & 3 deletions src/Core/Schema/Hierarchy/HierarchicalNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Apitte\Core\Schema\Hierarchy;

use Nette\Utils\Strings;

class HierarchicalNode
{

Expand Down Expand Up @@ -66,7 +64,7 @@ public function getSortedNodes(): array
// Divide static and variable nodes
foreach ($this->nodes as $node) {
$path = $node->getPath();
if (Strings::contains($path, '{') && Strings::contains($path, '}')) {
if (str_contains($path, '{') && str_contains($path, '}')) {
$variableNodes[] = $node;
} else {
$staticNodes[] = $node;
Expand Down
7 changes: 3 additions & 4 deletions src/OpenApi/DI/OpenApiPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use Nette\PhpGenerator\ClassType;
use Nette\Schema\Expect;
use Nette\Schema\Schema;
use Nette\Utils\Strings;
use stdClass;

/**
Expand Down Expand Up @@ -57,11 +56,11 @@ public function loadPluginConfiguration(): void
->addSetup('addDefinition', [new BaseDefinition()])
->addSetup('addDefinition', [$coreDefinition]);
foreach ($config->files as $file) {
if (Strings::endsWith($file, '.neon')) {
if (str_ends_with($file, '.neon')) {
$schemaBuilder->addSetup('addDefinition', [new NeonDefinition($file)]);
} elseif (Strings::endsWith($file, '.yaml') || Strings::endsWith($file, '.yml')) {
} elseif (str_ends_with($file, '.yaml') || str_ends_with($file, '.yml')) {
$schemaBuilder->addSetup('addDefinition', [new YamlDefinition($file)]);
} elseif (Strings::endsWith($file, '.json')) {
} elseif (str_ends_with($file, '.json')) {
$schemaBuilder->addSetup('addDefinition', [new JsonDefinition($file)]);
} else {
throw new InvalidArgumentException(sprintf(
Expand Down
6 changes: 3 additions & 3 deletions src/OpenApi/SchemaDefinition/Entity/EntityAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public function getMetadata(string $type): array
// Normalize null type
$type = str_replace('?', 'null|', $type);

$usesUnionType = Strings::contains($type, '|');
$usesIntersectionType = Strings::contains($type, '&');
$usesUnionType = str_contains($type, '|');
$usesIntersectionType = str_contains($type, '&');

// Get schema for all possible types
if ($usesUnionType || $usesIntersectionType) {
Expand Down Expand Up @@ -73,7 +73,7 @@ public function getMetadata(string $type): array
}

// Get schema for array
if (Strings::endsWith($type, '[]')) {
if (str_ends_with($type, '[]')) {
$subType = Strings::replace($type, '#\\[\\]#', '');
return [
Expand Down
2 changes: 1 addition & 1 deletion src/OpenApi/SchemaDefinition/JsonDefinition.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function load(): array
throw new InvalidStateException('Cant read file ' . $this->file);
}

$decode = Json::decode($content, Json::FORCE_ARRAY);
$decode = Json::decode($content, forceArrays: true);
if ($decode === false || $decode === null) {
return [];
}
Expand Down

0 comments on commit 1c37255

Please sign in to comment.