Skip to content
Permalink
Browse files

Merge pull request #74 from ergebnis/fix/isset

Fix: Avoid use of isset()
  • Loading branch information
localheinz committed Mar 23, 2020
2 parents 9f10354 + 168a715 commit 581abf8b49b31e80a2cc8246e3fbe0f4e5ce2963
Showing with 13 additions and 30 deletions.
  1. +0 −15 phpstan-baseline.neon
  2. +6 −9 psalm-baseline.xml
  3. +1 −1 src/EntityDef.php
  4. +6 −5 src/FixtureFactory.php
@@ -1,10 +1,5 @@
parameters:
ignoreErrors:
-
message: "#^Language construct isset\\(\\) should not be used\\.$#"
count: 1
path: src/EntityDef.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\EntityDef\\:\\:getFieldDefinitions\\(\\) has no return typehint specified\\.$#"
count: 1
@@ -40,16 +35,6 @@ parameters:
count: 1
path: src/FieldDef.php

-
message: "#^Language construct isset\\(\\) should not be used\\.$#"
count: 5
path: src/FixtureFactory.php

-
message: "#^Variable \\$classMetadata in isset\\(\\) always exists and is not nullable\\.$#"
count: 1
path: src/FixtureFactory.php

-
message: "#^Method Ergebnis\\\\FactoryBot\\\\FixtureFactory\\:\\:get\\(\\) has no return typehint specified\\.$#"
count: 1
@@ -5,8 +5,8 @@
<code>$fieldDefinition</code>
</InvalidArgument>
<MissingClosureReturnType occurrences="4">
<code>static function () use ($defaultFieldValue) {</code>
<code>static function () {</code>
<code>static function () use ($defaultFieldValue) {</code>
<code>static function () use ($fieldDefinition) {</code>
<code>static function () use ($fieldDefinition) {</code>
</MissingClosureReturnType>
@@ -56,9 +56,6 @@
</MixedOperand>
</file>
<file src="src/FixtureFactory.php">
<DocblockTypeContradiction occurrences="1">
<code>isset($classMetadata)</code>
</DocblockTypeContradiction>
<MissingParamType occurrences="8">
<code>$entity</code>
<code>$fieldName</code>
@@ -75,15 +72,18 @@
<code>getAsSingleton</code>
<code>createCollectionFrom</code>
</MissingReturnType>
<MixedArgument occurrences="18">
<MixedArgument occurrences="21">
<code>$name</code>
<code>$name</code>
<code>$type</code>
<code>$type</code>
<code>$name</code>
<code>$name</code>
<code>$name</code>
<code>$fieldName</code>
<code>$name</code>
<code>$name</code>
<code>$name</code>
<code>$entityDefinition-&gt;getFieldDefinitions()</code>
<code>$fieldName</code>
<code>$entity</code>
@@ -98,18 +98,15 @@
<MixedArrayAccess occurrences="1">
<code>$association['inversedBy']</code>
</MixedArrayAccess>
<MixedArrayOffset occurrences="11">
<code>$this-&gt;entityDefinitions[$name]</code>
<MixedArrayOffset occurrences="8">
<code>$this-&gt;entityDefinitions[$name]</code>
<code>$this-&gt;singletons[$name]</code>
<code>$this-&gt;singletons[$name]</code>
<code>$fieldOverrides[$fieldName]</code>
<code>$fieldValues[$fieldName]</code>
<code>$this-&gt;singletons[$name]</code>
<code>$this-&gt;singletons[$name]</code>
<code>$this-&gt;singletons[$name]</code>
<code>$this-&gt;singletons[$name]</code>
<code>$this-&gt;singletons[$name]</code>
</MixedArrayOffset>
<MixedAssignment occurrences="9">
<code>$type</code>
@@ -62,7 +62,7 @@ public function __construct(ORM\Mapping\ClassMetadata $classMetadata, array $fie
);

foreach ($fieldNames as $fieldName) {
if (isset($this->fieldDefinitions[$fieldName])) {
if (\array_key_exists($fieldName, $this->fieldDefinitions)) {
continue;
}

@@ -64,7 +64,7 @@ public function __construct(ORM\EntityManagerInterface $entityManager)
*/
public function defineEntity($name, array $fieldDefinitions = [], array $configuration = [])
{
if (isset($this->entityDefinitions[$name])) {
if (\array_key_exists($name, $this->entityDefinitions)) {
throw new \Exception(\sprintf(
"Entity '%s' already defined in fixture factory",
$name
@@ -80,9 +80,10 @@ public function defineEntity($name, array $fieldDefinitions = [], array $configu
));
}

/** @var null|ORM\Mapping\ClassMetadata $classMetadata */
$classMetadata = $this->entityManager->getClassMetadata($type);

if (!isset($classMetadata)) {
if (null === $classMetadata) {
throw new \Exception(\sprintf(
'Unknown entity type: %s',
$type
@@ -113,7 +114,7 @@ public function defineEntity($name, array $fieldDefinitions = [], array $configu
*/
public function get($name, array $fieldOverrides = [])
{
if (isset($this->singletons[$name])) {
if (\array_key_exists($name, $this->singletons)) {
return $this->singletons[$name];
}

@@ -145,7 +146,7 @@ public function get($name, array $fieldOverrides = [])
$this->setField($entity, $entityDefinition, $fieldName, $fieldValue);
}

if (isset($configuration['afterCreate'])) {
if (\array_key_exists('afterCreate', $configuration)) {
$configuration['afterCreate']($entity, $fieldValues);
}

@@ -209,7 +210,7 @@ public function persistOnGet($enabled = true): void
*/
public function getAsSingleton($name, array $fieldOverrides = [])
{
if (isset($this->singletons[$name])) {
if (\array_key_exists($name, $this->singletons)) {
throw new \Exception(\sprintf(
'Already a singleton: %s',
$name

0 comments on commit 581abf8

Please sign in to comment.
You can’t perform that action at this time.