Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] Add + Apply Coding Standards: PSR12, PHP 7.0, PHP 7.1 #435

Merged
merged 6 commits into from Dec 9, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -32,7 +32,7 @@ jobs:
-
<<: *POSTGRES_JOB
php: '7.2'
install:
install:
- composer update --prefer-lowest

# MySQL
@@ -59,7 +59,7 @@ jobs:
-
<<: *MYSQL_JOB
php: '7.2'
install:
install:
- composer update --prefer-lowest

-
@@ -21,14 +21,20 @@
"ext-pdo_pgsql": "*",
"doctrine/orm": "^2.6",
"phpunit/phpunit": "^8.4",
"jakub-onderka/php-parallel-lint": "^1.0"
},
"suggest": {
"symfony/framework-bundle": "To be able to use it as a bundle"
"jakub-onderka/php-parallel-lint": "^1.0",
"symplify/easy-coding-standard": "^7.1"
},
"autoload": {
"psr-4": {
"Knp\\DoctrineBehaviors\\": "src"
}
},
"suggest": {
"symfony/framework-bundle": "To be able to use it as a bundle"
},
"scripts": {
"check-cs": "ecs check src tests --ansi",
"fix-cs": "ecs check src tests --fix --ansi",
"phpstan": "phpstan analyse src tests --ansi"
}
}
@@ -0,0 +1,11 @@
parameters:
sets:
- 'psr12'
- 'php70'
- 'php71'
# - 'symplify'
# - 'common'
- 'clean-code'

skip:
PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: null
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\Bundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
@@ -23,15 +25,15 @@ public function getConfigTreeBuilder()
->always(function (array $config) {
if (empty($config)) {
return [
'blameable' => true,
'geocodable' => true,
'loggable' => true,
'sluggable' => true,
'blameable' => true,
'geocodable' => true,
'loggable' => true,
'sluggable' => true,
'soft_deletable' => true,
'sortable' => true,
'timestampable' => true,
'translatable' => true,
'tree' => true,
'sortable' => true,
'timestampable' => true,
'translatable' => true,
'tree' => true,
];
}

@@ -1,9 +1,10 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\Bundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
@@ -13,9 +14,9 @@ class DoctrineBehaviorsExtension extends Extension
/**
* {@inheritDoc}
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$loader = new YamlFileLoader($container, new FileLocator(__DIR__.'/../../../config'));
$loader = new YamlFileLoader($container, new FileLocator(__DIR__ . '/../../../config'));
$loader->load('orm-services.yml');

$configuration = new Configuration();
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\Bundle;

use Knp\DoctrineBehaviors\Bundle\DependencyInjection\DoctrineBehaviorsExtension;
@@ -1,10 +1,12 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\DBAL\Types;

use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Types\Type;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

/**
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -19,7 +21,7 @@
trait BlameableMethods
{
/**
* @param mixed the user representation
* @param mixed $user the user representation
* @return $this
*/
public function setCreatedBy($user)
@@ -30,7 +32,7 @@ public function setCreatedBy($user)
}

/**
* @param mixed the user representation
* @param mixed $user the user representation
* @return $this
*/
public function setUpdatedBy($user)
@@ -41,7 +43,7 @@ public function setUpdatedBy($user)
}

/**
* @param mixed the user representation
* @param mixed $user the user representation
* @return $this
*/
public function setDeletedBy($user)
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -11,8 +13,6 @@

namespace Knp\DoctrineBehaviors\Model\Geocodable;

use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

/**
* Geocodable trait.
*
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -37,7 +39,7 @@ public function getLocation()
*
* @return $this
*/
public function setLocation(Point $location = null)
public function setLocation(?Point $location = null)
{
$this->location = $location;

@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -11,8 +13,6 @@

namespace Knp\DoctrineBehaviors\Model\Geocodable;

use Knp\DoctrineBehaviors\ORM\Geocodable\Type\Point;

/**
* Geocodable trait.
*
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/**
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author Lusitanian
* Freely released with no restrictions, re-license however you'd like!
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author Lusitanian
* Freely released with no restrictions, re-license however you'd like!
@@ -53,7 +56,7 @@ public function setSlug($slug)

return $this;
}

/**
* Returns the entity's slug.
*
@@ -71,36 +74,34 @@ public function getSlug()
private function generateSlugValue($values)
{
$usableValues = [];
foreach ($values as $fieldName => $fieldValue) {
foreach ($values as $fieldValue) {
if (!empty($fieldValue)) {
$usableValues[] = $fieldValue;
}
}

if (count($usableValues) < 1) {
throw new \UnexpectedValueException(
'Sluggable expects to have at least one usable (non-empty) field from the following: [ ' . implode(array_keys($values), ',') .' ]'
'Sluggable expects to have at least one usable (non-empty) field from the following: [ ' . implode(array_keys($values), ',') . ' ]'
);
}

// generate the slug itself
$sluggableText = implode(' ', $usableValues);

$transliterator = new Transliterator;
$transliterator = new Transliterator();
$sluggableText = $transliterator->transliterate($sluggableText, $this->getSlugDelimiter());

$urlized = strtolower( trim( preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $sluggableText ), $this->getSlugDelimiter() ) );
$urlized = preg_replace("/[\/_|+ -]+/", $this->getSlugDelimiter(), $urlized);

return $urlized;
$urlized = strtolower(trim(preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $sluggableText), $this->getSlugDelimiter()));
return preg_replace("/[\/_|+ -]+/", $this->getSlugDelimiter(), $urlized);
}

/**
* Generates and sets the entity's slug. Called prePersist and preUpdate
*/
public function generateSlug()
public function generateSlug(): void
{
if ( $this->getRegenerateSlugOnUpdate() || empty( $this->slug ) ) {
if ($this->getRegenerateSlugOnUpdate() || empty($this->slug)) {
$fields = $this->getSluggableFields();
$values = [];

@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author Lusitanian
* Freely released with no restrictions, re-license however you'd like!
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @author Lusitanian
* Freely released with no restrictions, re-license however you'd like!
@@ -11,5 +14,4 @@
*/
class Transliterator extends \Behat\Transliterator\Transliterator
{

}
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -21,15 +23,15 @@ trait SoftDeletableMethods
/**
* Marks entity as deleted.
*/
public function delete()
public function delete(): void
{
$this->deletedAt = $this->currentDateTime();
}

/**
* Restore entity by undeleting it
*/
public function restore()
public function restore(): void
{
$this->deletedAt = null;
}
@@ -53,14 +55,12 @@ public function isDeleted()
*
* @return Boolean
*/
public function willBeDeleted(\DateTime $at = null)
public function willBeDeleted(?\DateTime $at = null)
{
if ($this->deletedAt === null) {

return false;
}
if ($at === null) {

return true;
}

@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

/*
* This file is part of the KnpDoctrineBehaviors package.
*
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace Knp\DoctrineBehaviors\Model\Sortable;

trait Sortable
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.