Skip to content

Commit

Permalink
phpstan 0.12 + psr-12
Browse files Browse the repository at this point in the history
  • Loading branch information
janatjak committed Dec 14, 2019
1 parent 819ef56 commit 35ab2b7
Show file tree
Hide file tree
Showing 27 changed files with 69 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- stage: Code Static Analyze (phpstan)
php: 7.3
script:
- php vendor/bin/phpstan.phar analyse ./src ./tests --level 7
- php vendor/bin/phpstan analyse ./src ./tests --level max

- stage: Code Standard Checker
php: 7.3
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@
"nette/di": "~2.4 || ^3.0",
"nette/forms": "~2.4 || ^3.0",
"doctrine/orm": "~2.5",
"symfony/property-access": "~3.0 || ^4.0"
"symfony/property-access": "~3.0 || ^4.0 || ^5.0"
},
"require-dev": {
"latte/latte": "~2.5",
"nette/application": "~2.4 || ^3.0",
"nette/bootstrap": "~2.4 || ^3.0",
"nette/tester": "~2.0",
"phpstan/phpstan-shim": "^0.11",
"phpstan/phpstan": "^0.12",
"ramsey/uuid-doctrine": "^1.5",
"squizlabs/php_codesniffer": "^3.0",
"tracy/tracy": "^2.5"
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
parameters:
ignoreErrors:
- '#ReflectionClass#'
- '#ManyToOne::findPairs\(\)#'
2 changes: 2 additions & 0 deletions src/DI/FormMapperExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand All @@ -24,6 +25,7 @@
*/
class FormMapperExtension extends CompilerExtension
{
/** @var mixed[] */
private $defaults = [
'mappers' => [
Construct::class,
Expand Down
1 change: 1 addition & 0 deletions src/DoctrineFormMapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
1 change: 1 addition & 0 deletions src/Exceptions/InvalidStateException.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
1 change: 1 addition & 0 deletions src/IComponentMapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
1 change: 1 addition & 0 deletions src/Mappers/Column.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
9 changes: 5 additions & 4 deletions src/Mappers/Construct.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down Expand Up @@ -68,7 +69,7 @@ public function save(ClassMetadata $meta, Component $component, &$entity): bool
throw new InvalidStateException(__METHOD__ . ' cannot found container');
}

foreach ($constructor->getParameters() as $constructorParameter) {
foreach ($constructor->getParameters() as $i => $constructorParameter) {
// property name
$name = $constructorParameter->getName();

Expand All @@ -89,7 +90,7 @@ public function save(ClassMetadata $meta, Component $component, &$entity): bool
throw new InvalidStateException('Scalar type and form container? What is wrong with you?');
}
// scalar type
$constructorNewParameters[$name] = $child->getValue();
$constructorNewParameters[$i] = $child->getValue();
continue;
}

Expand All @@ -100,9 +101,9 @@ public function save(ClassMetadata $meta, Component $component, &$entity): bool
// probably OneToOne Container
$this->save($this->entityManager->getClassMetadata($targetClass), $child, $targetClass);
// $targetClass is new instance
$constructorNewParameters[$name] = $targetClass;
$constructorNewParameters[$i] = $targetClass;
} elseif ($child instanceof BaseControl) {
$constructorNewParameters[$name] = $this->entityManager->find($targetClass, $child->getValue());
$constructorNewParameters[$i] = $this->entityManager->find($targetClass, $child->getValue());
}
}

Expand Down
1 change: 1 addition & 0 deletions src/Mappers/Embedded.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
17 changes: 14 additions & 3 deletions src/Mappers/ManyToMany.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand All @@ -16,6 +17,7 @@
use Nette\ComponentModel\Component;
use Nette\Forms\Controls\MultiChoiceControl;
use Nette\SmartObject;
use TypeError;

/**
* @author Jakub Janata <[email protected]>
Expand Down Expand Up @@ -44,8 +46,17 @@ public function load(ClassMetadata $meta, Component $component, $entity): bool
// set default items
$this->setDefaultItems($component, $entity);

/** @var Collection|null $collection */
$collection = $this->accessor->getValue($entity, $name);
/** @var Collection<int|string, mixed>|null $collection */
$collection = null;

try {
$collection = $this->accessor->getValue($entity, $name);
} catch (TypeError $error) {
$pattern = '/must be (of the type|an instance of) .*, null returned$/';
if (!preg_match($pattern, $error->getMessage())) {
throw $error;
}
}

if ($collection) {
$UoW = $this->em->getUnitOfWork();
Expand Down Expand Up @@ -78,7 +89,7 @@ public function save(ClassMetadata $meta, Component $component, &$entity): bool

$valueIdentifiers = $component->getValue();

/** @var Collection $collection */
/** @var Collection<int|string, mixed> $collection */
$collection = $this->accessor->getValue($entity, $name);
$collection->clear();

Expand Down
1 change: 1 addition & 0 deletions src/Mappers/ManyToOne.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
1 change: 1 addition & 0 deletions src/Mappers/OneToOne.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
7 changes: 4 additions & 3 deletions src/Utils/RelationsHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down Expand Up @@ -81,9 +82,9 @@ protected function relatedMetadata($entity, string $relationName): ClassMetadata
/**
* @param ClassMetadata $meta
* @param callable|string $associationKeyOrCallback
* @param array $criteria
* @param array $orderBy
* @return array
* @param string[] $criteria
* @param string[] $orderBy
* @return mixed[]
*/
protected function findPairs(ClassMetadata $meta, $associationKeyOrCallback, array $criteria, array $orderBy): array
{
Expand Down
1 change: 1 addition & 0 deletions tests/Mock/CustomService.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace FreezyBee\DoctrineFormMapper\Tests\Mock;
Expand Down
1 change: 1 addition & 0 deletions tests/Mock/CustomServiceMapper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace FreezyBee\DoctrineFormMapper\Tests\Mock;
Expand Down
3 changes: 2 additions & 1 deletion tests/Mock/Entity/Address.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getStreet(): string
/**
* @param string $street
*/
public function setStreet(string $street)
public function setStreet(string $street): void
{
$this->street = $street;
}
Expand Down
16 changes: 9 additions & 7 deletions tests/Mock/Entity/Article.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand All @@ -10,6 +11,7 @@
namespace FreezyBee\DoctrineFormMapper\Tests\Mock\Entity;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;

/**
Expand Down Expand Up @@ -38,7 +40,7 @@ class Article
private $author;

/**
* @var Tag[]|ArrayCollection
* @var Tag[]|Collection<int,Tag>
* @ORM\ManyToMany(targetEntity="Tag")
*/
private $tags;
Expand Down Expand Up @@ -71,7 +73,7 @@ public function getTitle(): string
/**
* @param string $title
*/
public function setTitle(string $title)
public function setTitle(string $title): void
{
$this->title = $title;
}
Expand All @@ -87,23 +89,23 @@ public function getAuthor(): Author
/**
* @param Author $author
*/
public function setAuthor(Author $author)
public function setAuthor(Author $author): void
{
$this->author = $author;
}

/**
* @return ArrayCollection|Tag[]
* @return Tag[]|Collection<int,Tag>
*/
public function getTags()
public function getTags(): Collection
{
return $this->tags;
}

/**
* @param ArrayCollection|Tag[] $tags
* @param Tag[]|Collection<int,Tag> $tags
*/
public function setTags($tags)
public function setTags($tags): void
{
$this->tags = $tags;
}
Expand Down
9 changes: 5 additions & 4 deletions tests/Mock/Entity/Author.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down Expand Up @@ -77,7 +78,7 @@ public function getName(): string
/**
* @param string $name
*/
public function setName(string $name)
public function setName(string $name): void
{
$this->name = $name;
}
Expand All @@ -93,7 +94,7 @@ public function getAge(): int
/**
* @param int $age
*/
public function setAge(int $age)
public function setAge(int $age): void
{
$this->age = $age;
}
Expand All @@ -109,15 +110,15 @@ public function getAddress(): Address
/**
* @return Car|null
*/
public function getCar()
public function getCar(): ?Car
{
return $this->car;
}

/**
* @param Car|null $car
*/
public function setCar($car)
public function setCar($car): void
{
$this->car = $car;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Mock/Entity/Car.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getLicense(): string
/**
* @param string $license
*/
public function setLicense(string $license)
public function setLicense(string $license): void
{
$this->license = $license;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Mock/Entity/EmbeddableFrog.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function getName(): string
/**
* @param string $name
*/
public function setName(string $name)
public function setName(string $name): void
{
$this->name = $name;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Mock/Entity/ImmutableThing.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace FreezyBee\DoctrineFormMapper\Tests\Mock\Entity;
Expand Down Expand Up @@ -54,7 +55,7 @@ public function getText(): string
* @param string $name
* @param mixed $value
*/
public function __set($name, $value)
public function __set($name, $value): void
{
throw new LogicException();
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Mock/Entity/Pond.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function getId(): int
/**
* @param int $id
*/
public function setId(int $id)
public function setId(int $id): void
{
$this->id = $id;
}
Expand All @@ -59,7 +59,7 @@ public function getFrog(): EmbeddableFrog
/**
* @param EmbeddableFrog $frog
*/
public function setFrog(EmbeddableFrog $frog)
public function setFrog(EmbeddableFrog $frog): void
{
$this->frog = $frog;
}
Expand Down
3 changes: 2 additions & 1 deletion tests/Mock/Entity/Tag.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down Expand Up @@ -49,7 +50,7 @@ public function getName(): string
/**
* @param string $name
*/
public function setName($name)
public function setName($name): void
{
$this->name = $name;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Mock/Entity/TestDate.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

/*
Expand Down
Loading

0 comments on commit 35ab2b7

Please sign in to comment.