Skip to content
This repository has been archived by the owner on Jul 22, 2022. It is now read-only.

Commit

Permalink
Merge 77c8487 into 0288adf
Browse files Browse the repository at this point in the history
  • Loading branch information
SonataCI committed Feb 6, 2019
2 parents 0288adf + 77c8487 commit dec08bb
Show file tree
Hide file tree
Showing 31 changed files with 89 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Expand Up @@ -7,7 +7,7 @@ charset = utf-8
insert_final_newline = true
trim_trailing_whitespace = true

[*.{yml,twig,php}]
[*.{yaml,yml,twig,php}]
indent_size = 4

[*.{js,json,scss,css}]
Expand Down
7 changes: 3 additions & 4 deletions .php_cs.dist
Expand Up @@ -43,10 +43,9 @@ $rules = [
'@PHP71Migration:risky' => true,
'compact_nullable_typehint' => true,
'void_return' => null,
// To be tested before insertion:
// 'strict_comparison' => true,
// 'strict_param' => true,
// 'php_unit_strict' => true,
'strict_comparison' => true,
'strict_param' => true,
'php_unit_strict' => true,
];


Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Expand Up @@ -15,8 +15,7 @@ php:
- '7.3'
- nightly

sudo: false
dist: trusty
dist: xenial

addons:
apt:
Expand Down
18 changes: 16 additions & 2 deletions Makefile
Expand Up @@ -51,8 +51,22 @@ cs-fix-xml:
done
.PHONY: cs-fix-xml

test:
phpunit -c phpunit.xml.dist --coverage-clover build/logs/clover.xml
build:
mkdir $@

HAS_XDEBUG=$(shell php --modules|grep --quiet xdebug;echo $$?)

build/xdebug-filter.php: phpunit.xml.dist build
ifeq ($(HAS_XDEBUG), 0)
phpunit --dump-xdebug-filter $@
endif

test: build/xdebug-filter.php
ifeq ($(HAS_XDEBUG), 0)
phpunit --prepend build/xdebug-filter.php -c phpunit.xml.dist --coverage-clover build/logs/clover.xml
else
phpunit -c phpunit.xml.dist
endif
.PHONY: test

docs:
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/DatagridBuilder.php
Expand Up @@ -103,7 +103,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
if (isset($metadata->mappings[$fieldDescription->getName()])) {
$fieldDescription->setFieldMapping($metadata->mappings[$fieldDescription->getName()]);

if ('string' == $metadata->mappings[$fieldDescription->getName()]['type']) {
if ('string' === $metadata->mappings[$fieldDescription->getName()]['type']) {
$fieldDescription->setOption('global_search', $fieldDescription->getOption('global_search', true)); // always search on string field only
}
}
Expand All @@ -125,7 +125,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
*/
public function addFilter(DatagridInterface $datagrid, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if (null == $type) {
if (null === $type) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$type = $guessType->getType();
$fieldDescription->setType($type);
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/FormContractor.php
Expand Up @@ -79,7 +79,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
'referrers',
];

if ($metadata && $metadata->hasAssociation($fieldDescription->getName()) && \in_array($fieldDescription->getMappingType(), $mappingTypes)) {
if ($metadata && $metadata->hasAssociation($fieldDescription->getName()) && \in_array($fieldDescription->getMappingType(), $mappingTypes, true)) {
$admin->attachAdminClass($fieldDescription);
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Builder/ListBuilder.php
Expand Up @@ -56,7 +56,7 @@ public function getBaseList(array $options = [])
*/
public function buildField($type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if (null == $type) {
if (null === $type) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType instanceof TypeGuess ? $guessType->getType() : null);
} else {
Expand Down Expand Up @@ -84,7 +84,7 @@ public function addField(FieldDescriptionCollection $list, $type, FieldDescripti
*/
public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInterface $fieldDescription)
{
if ('_action' == $fieldDescription->getName() || 'actions' === $fieldDescription->getType()) {
if ('_action' === $fieldDescription->getName() || 'actions' === $fieldDescription->getType()) {
$this->buildActionFieldDescription($fieldDescription);
}

Expand Down Expand Up @@ -163,19 +163,19 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));

if (ClassMetadata::MANY_TO_ONE == $fieldDescription->getMappingType()) {
if (ClassMetadata::MANY_TO_ONE === $fieldDescription->getMappingType()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/list_many_to_one.html.twig');
}

if (ClassMetadata::MANY_TO_MANY == $fieldDescription->getMappingType()) {
if (ClassMetadata::MANY_TO_MANY === $fieldDescription->getMappingType()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/list_many_to_many.html.twig');
}

if ('child' == $fieldDescription->getMappingType() || 'parent' == $fieldDescription->getMappingType()) {
if ('child' === $fieldDescription->getMappingType() || 'parent' === $fieldDescription->getMappingType()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/list_one_to_one.html.twig');
}

if ('children' == $fieldDescription->getMappingType() || 'referrers' == $fieldDescription->getMappingType()) {
if ('children' === $fieldDescription->getMappingType() || 'referrers' === $fieldDescription->getMappingType()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/list_one_to_many.html.twig');
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/ShowBuilder.php
Expand Up @@ -55,7 +55,7 @@ public function getBaseList(array $options = [])
*/
public function addField(FieldDescriptionCollection $list, $type, FieldDescriptionInterface $fieldDescription, AdminInterface $admin)
{
if (null == $type) {
if (null === $type) {
$guessType = $this->guesser->guessType($admin->getClass(), $fieldDescription->getName(), $admin->getModelManager());
$fieldDescription->setType($guessType->getType());
} else {
Expand Down Expand Up @@ -105,11 +105,11 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
if (!$fieldDescription->getTemplate()) {
$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));

if (ClassMetadata::MANY_TO_ONE == $fieldDescription->getMappingType()) {
if (ClassMetadata::MANY_TO_ONE === $fieldDescription->getMappingType()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/show_many_to_one.html.twig');
}

if (ClassMetadata::MANY_TO_MANY == $fieldDescription->getMappingType()) {
if (ClassMetadata::MANY_TO_MANY === $fieldDescription->getMappingType()) {
$fieldDescription->setTemplate('@SonataAdmin/CRUD/Association/show_many_to_many.html.twig');
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/AutocompleteController.php
Expand Up @@ -110,7 +110,7 @@ public function autoCompleteAction(Request $request)
}

//did we max out x+1
$more = (\count($results) == $itemsPerPage + 1);
$more = (\count($results) === $itemsPerPage + 1);
$method = $request->get('_method_name');

$items = [];
Expand Down
6 changes: 3 additions & 3 deletions src/Controller/TreeController.php
Expand Up @@ -104,18 +104,18 @@ public function reorderAction(Request $request)
return new JsonResponse(['Parameters parent, dropped and target has to be set to reorder.'], Response::HTTP_BAD_REQUEST);
}

if (\in_array($position, ['over', 'child'])) {
if (\in_array($position, ['over', 'child'], true)) {
return new JsonResponse(['Can not reorder when dropping into a collection.'], Response::HTTP_BAD_REQUEST);
}

$before = 'before' == $position;
$before = 'before' === $position;
$parentNode = $this->session->getNode($parentPath);
$targetName = PathHelper::getNodeName($targetPath);
if (!$before) {
$nodesIterator = $parentNode->getNodes();
$nodesIterator->rewind();
while ($nodesIterator->valid()) {
if ($nodesIterator->key() == $targetName) {
if ($nodesIterator->key() === $targetName) {
break;
}
$nodesIterator->next();
Expand Down
2 changes: 1 addition & 1 deletion src/Datagrid/Pager.php
Expand Up @@ -61,7 +61,7 @@ public function init()
$this->resetIterator();
$this->setNbResults($this->computeNbResult());

if (0 == $this->getPage() || 0 == $this->getMaxPerPage() || 0 == $this->getNbResults()) {
if (0 === $this->getPage() || 0 === $this->getMaxPerPage() || 0 === $this->getNbResults()) {
$this->setLastPage(0);
$this->getQuery()->setFirstResult(0);
$this->getQuery()->setMaxResults(0);
Expand Down
2 changes: 1 addition & 1 deletion src/Datagrid/ProxyQuery.php
Expand Up @@ -187,7 +187,7 @@ public function getSortBy()
*/
public function setSortOrder($sortOrder)
{
if (!\in_array($sortOrder, ['ASC', 'DESC'])) {
if (!\in_array($sortOrder, ['ASC', 'DESC'], true)) {
throw new \InvalidArgumentException(sprintf('The parameter $sortOrder must be one of "ASC" or "DESC", got "%s"', $sortOrder));
}
$this->sortOrder = $sortOrder;
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/Compiler/AddTemplatesCompilerPass.php
Expand Up @@ -29,7 +29,7 @@ public function process(ContainerBuilder $container)
{
$settings = $this->fixSettings($container);
foreach ($container->findTaggedServiceIds('sonata.admin') as $id => $attributes) {
if (!isset($attributes[0]['manager_type']) || 'doctrine_phpcr' != $attributes[0]['manager_type']) {
if (!isset($attributes[0]['manager_type']) || 'doctrine_phpcr' !== $attributes[0]['manager_type']) {
continue;
}

Expand Down Expand Up @@ -60,7 +60,7 @@ protected function fixSettings(ContainerBuilder $container)
$settings = false;
$methods = $pool->getMethodCalls();
foreach ($methods as $pos => $calls) {
if ('__hack_doctrine_phpcr__' == $calls[0]) {
if ('__hack_doctrine_phpcr__' === $calls[0]) {
$settings = $calls[1];

break;
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/BooleanFilter.php
Expand Up @@ -33,7 +33,7 @@ public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data)
}

$where = $this->getWhere($proxyQuery);
$where->eq()->field('a.'.$field)->literal(BooleanType::TYPE_YES == $data['value'] ? true : false);
$where->eq()->field('a.'.$field)->literal(BooleanType::TYPE_YES === $data['value'] ? true : false);

// filter is active as we have now modified the query
$this->active = true;
Expand Down
6 changes: 3 additions & 3 deletions src/Filter/ChoiceFilter.php
Expand Up @@ -48,11 +48,11 @@ public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data)
$andX = $this->getWhere($proxyQuery)->andX();

foreach ($values as $value) {
if (ChoiceType::TYPE_NOT_CONTAINS == $type) {
if (ChoiceType::TYPE_NOT_CONTAINS === $type) {
$andX->not()->like()->field('a.'.$field)->literal('%'.$value.'%');
} elseif (ChoiceType::TYPE_CONTAINS == $type) {
} elseif (ChoiceType::TYPE_CONTAINS === $type) {
$andX->like()->field('a.'.$field)->literal('%'.$value.'%');
} elseif (ChoiceType::TYPE_EQUAL == $type) {
} elseif (ChoiceType::TYPE_EQUAL === $type) {
$andX->like()->field('a.'.$field)->literal($value);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Filter/Filter.php
Expand Up @@ -49,7 +49,7 @@ public function isActive()
protected function getWhere(ProxyQuery $proxy)
{
$queryBuilder = $proxy->getQueryBuilder();
if (self::CONDITION_OR == $this->getCondition()) {
if (self::CONDITION_OR === $this->getCondition()) {
return $queryBuilder->orWhere();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Filter/NodeNameFilter.php
Expand Up @@ -30,7 +30,7 @@ public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data)
$data['value'] = trim((string) $data['value']);
$data['type'] = empty($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];

if (0 == \strlen($data['value'])) {
if (0 === \strlen($data['value'])) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Filter/StringFilter.php
Expand Up @@ -30,7 +30,7 @@ public function filter(ProxyQueryInterface $proxyQuery, $alias, $field, $data)
$value = trim((string) $data['value']);
$data['type'] = empty($data['type']) ? ChoiceType::TYPE_CONTAINS : $data['type'];

if (0 == \strlen($value)) {
if (0 === \strlen($value)) {
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Form/Extension/CollectionTypeExtension.php
Expand Up @@ -29,7 +29,7 @@ class CollectionTypeExtension extends AbstractTypeExtension
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
if ('doctrine_phpcr' != $options['sonata_field_description']->getAdmin()->getManagerType() || !$options['sonata_field_description']->getOption('sortable')) {
if ('doctrine_phpcr' !== $options['sonata_field_description']->getAdmin()->getManagerType() || !$options['sonata_field_description']->getOption('sortable')) {
return;
}
$listener = new CollectionOrderListener($options['sonata_field_description']->getName());
Expand Down
6 changes: 3 additions & 3 deletions src/Model/ModelManager.php
Expand Up @@ -347,7 +347,7 @@ public function batchDelete($class, ProxyQueryInterface $queryProxy)
foreach ($res as $object) {
$this->dm->remove($object);

if (0 == (++$i % 20)) {
if (0 === (++$i % 20)) {
$this->dm->flush();
$this->dm->clear();
}
Expand Down Expand Up @@ -377,8 +377,8 @@ public function getSortParameters(FieldDescriptionInterface $fieldDescription, D
{
$values = $datagrid->getValues();

if ($fieldDescription->getName() == $values['_sort_by']->getName()) {
if ('ASC' == $values['_sort_order']) {
if ($fieldDescription->getName() === $values['_sort_by']->getName()) {
if ('ASC' === $values['_sort_order']) {
$values['_sort_order'] = 'DESC';
} else {
$values['_sort_order'] = 'ASC';
Expand Down
6 changes: 3 additions & 3 deletions tests/Unit/Datagrid/PagerTest.php
Expand Up @@ -45,7 +45,7 @@ public function testInitNumPages(): void
$this->pager->setQuery($this->proxyQuery);
$this->pager->init();

$this->assertEquals(2, $this->pager->getLastPage());
$this->assertSame(2, $this->pager->getLastPage());
}

public function testInitOffset(): void
Expand All @@ -68,7 +68,7 @@ public function testInitOffset(): void
$this->pager->setPage(2);
$this->pager->init();

$this->assertEquals(2, $this->pager->getLastPage());
$this->assertSame(2, $this->pager->getLastPage());
}

public function testNoPagesPerConfig(): void
Expand All @@ -92,7 +92,7 @@ public function testNoPagesPerConfig(): void
$this->pager->setMaxPerPage(0);
$this->pager->init();

$this->assertEquals(0, $this->pager->getLastPage());
$this->assertSame(0, $this->pager->getLastPage());
}

public function testNoPagesForNoResults(): void
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/Datagrid/ProxyQueryTest.php
Expand Up @@ -47,21 +47,21 @@ public function testConstructor(): void
public function testSetSortBy(): void
{
$this->pq->setSortBy([], ['fieldName' => 'field']);
$this->assertEquals('field', $this->pq->getSortBy());
$this->assertSame('field', $this->pq->getSortBy());
}

public function testSetSortOrder(): void
{
$this->pq->setSortOrder('ASC');
$this->assertEquals('ASC', $this->pq->getSortOrder());
$this->assertSame('ASC', $this->pq->getSortOrder());
}

public function testSetSortOrderInvalid(): void
{
$this->expectException(\InvalidArgumentException::class);

$this->pq->setSortOrder('SOME_ORDER');
$this->assertEquals('SOME_ORDER', $this->pq->getSortOrder());
$this->assertSame('SOME_ORDER', $this->pq->getSortOrder());
}

public function testSetFirstResult(): void
Expand Down Expand Up @@ -108,13 +108,13 @@ public function testExecute(): void
->will($this->returnValue('test'));

$res = $this->pq->execute();
$this->assertEquals('test', $res);
$this->assertSame('test', $res);
}

public function testGetAndSetDocumentManager(): void
{
$dm = $this->createMock(DocumentManager::class);
$this->pq->setDocumentManager($dm);
$this->assertEquals($dm, $this->pq->getDocumentManager());
$this->assertSame($dm, $this->pq->getDocumentManager());
}
}
6 changes: 3 additions & 3 deletions tests/Unit/Filter/BooleanFilterTest.php
Expand Up @@ -76,9 +76,9 @@ public function testFilterSwitch($operatorMethod, $value, $expectedValue): void
$opDynamic = $this->qbTester->getNode('where.constraint.operand_dynamic');
$opStatic = $this->qbTester->getNode('where.constraint.operand_static');

$this->assertEquals('a', $opDynamic->getAlias());
$this->assertEquals('somefield', $opDynamic->getField());
$this->assertEquals($expectedValue, $opStatic->getValue());
$this->assertSame('a', $opDynamic->getAlias());
$this->assertSame('somefield', $opDynamic->getField());
$this->assertSame($expectedValue, $opStatic->getValue());

$this->assertTrue($this->filter->isActive());
}
Expand Down

0 comments on commit dec08bb

Please sign in to comment.