Skip to content

Commit

Permalink
Coding Standards
Browse files Browse the repository at this point in the history
  • Loading branch information
Lustmored committed Jan 26, 2021
1 parent c776207 commit ea8af53
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
12 changes: 6 additions & 6 deletions lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -1426,18 +1426,18 @@ protected function _validateAndCompleteFieldMapping(array &$mapping)
&& $this->reflClass->hasProperty($mapping['fieldName'])
) {
$property = $this->reflClass->getProperty($mapping['fieldName']);
$type = $property->getType();
$type = $property->getType();

if ($type) {
if (!isset($mapping['nullable'])) {
if ( ! isset($mapping['nullable'])) {
$mapping['nullable'] = $type->allowsNull();
}

if (
!isset($mapping['type'])
! isset($mapping['type'])
&& ($type instanceof ReflectionNamedType)
) {
switch($type->getName()) {
switch ($type->getName()) {
case DateInterval::class:
$mapping['type'] = 'dateinterval';
break;
Expand Down Expand Up @@ -1570,7 +1570,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)
&& $this->reflClass->hasProperty($mapping['fieldName'])
) {
$property = $this->reflClass->getProperty($mapping['fieldName']);
$type = $property->getType();
$type = $property->getType();

if (
! isset($mapping['targetEntity'])
Expand All @@ -1582,7 +1582,7 @@ protected function _validateAndCompleteAssociationMapping(array $mapping)

if ($type !== null && isset($mapping['joinColumns'])) {
foreach ($mapping['joinColumns'] as &$joinColumn) {
if (!isset($joinColumn['nullable'])) {
if ( ! isset($joinColumn['nullable'])) {
$joinColumn['nullable'] = $type->allowsNull();
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Doctrine/Tests/Models/CMS/CmsUserTyped.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\Models\CMS;
Expand Down Expand Up @@ -29,6 +30,7 @@ class CmsUserTyped
public string $username;

/**
* @var string
* @Column(type="string", length=255)
*/
public $name;
Expand Down
8 changes: 4 additions & 4 deletions tests/Doctrine/Tests/ORM/Mapping/ClassMetadataTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function testFieldIsNullable()
$this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable.");
}

public function testFieldIsNullableByType()
public function testFieldIsNullableByType(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('requies PHP 7.4');
Expand All @@ -113,14 +113,14 @@ public function testFieldIsNullableByType()

// Implicit Not Nullable
$cm->mapField(['fieldName' => 'name', 'type' => 'string', 'length' => 50]);
$this->assertFalse($cm->isNullable('name'), "By default a field should not be nullable.");
$this->assertFalse($cm->isNullable('name'), 'By default a field should not be nullable.');

// Join table Nullable
$cm->mapOneToOne(['fieldName' => 'email', 'joinColumns' => [[]]]);
$this->assertFalse($cm->getAssociationMapping('email')['joinColumns'][0]['nullable']);
}

public function testFieldTypeFromReflection()
public function testFieldTypeFromReflection(): void
{
if (PHP_VERSION_ID < 70400) {
$this->markTestSkipped('requies PHP 7.4');
Expand All @@ -139,7 +139,7 @@ public function testFieldTypeFromReflection()

// Default string fallback
$cm->mapField(['fieldName' => 'name', 'type' => 'string', 'length' => 50]);
$this->assertEquals('string', $cm->getTypeOfField('name'), "By default a field should be string.");
$this->assertEquals('string', $cm->getTypeOfField('name'), 'By default a field should be string.');

// String
$cm->mapField(['fieldName' => 'dateInterval']);
Expand Down

0 comments on commit ea8af53

Please sign in to comment.