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

Commit

Permalink
PHP CS fixer
Browse files Browse the repository at this point in the history
  • Loading branch information
soullivaneuh committed Jun 16, 2015
1 parent 611e8e7 commit 0a3f730
Show file tree
Hide file tree
Showing 53 changed files with 364 additions and 325 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ vendor/
report/*
Resources/doc/_build/
composer.lock
.php_cs.cache
19 changes: 19 additions & 0 deletions .php_cs
@@ -0,0 +1,19 @@
<?php

$finder = Symfony\CS\Finder\DefaultFinder::create()
->in(array(__DIR__))
;

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers(array(
'-unalign_double_arrow',
'-unalign_equals',
'align_double_arrow',
'newline_after_open_tag',
'ordered_use',
'long_array_syntax',
))
->setUsingCache(true)
->finder($finder)
;
6 changes: 5 additions & 1 deletion .travis.yml
Expand Up @@ -23,6 +23,8 @@ env:
matrix:
fast_finish: true
include:
- php: 5.6
env: CS_FIXER=run
- php: 5.3
env: COMPOSER_FLAGS="--prefer-lowest"
- php: 5.6
Expand Down Expand Up @@ -51,7 +53,9 @@ before_script:
- export PATH=$HOME/.local/bin:$PATH
- pip install -r Resources/doc/requirements.txt --user `whoami`

script: make test
script:
- if [ "$CS_FIXER" = "run" ]; then make cs_dry_run ; fi;
- make test

notifications:
webhooks: https://sonata-project.org/bundles/doctrine-phpcr-admin/master/travis
Expand Down
6 changes: 3 additions & 3 deletions Admin/Admin.php
Expand Up @@ -14,8 +14,8 @@
use PHPCR\Util\PathHelper;
use PHPCR\Util\UUIDHelper;
use Sonata\AdminBundle\Admin\Admin as BaseAdmin;
use Sonata\AdminBundle\Route\RouteCollection;
use Sonata\AdminBundle\Datagrid\ProxyQueryInterface;
use Sonata\AdminBundle\Route\RouteCollection;

/**
* Extend the Admin class to incorporate phpcr changes.
Expand Down Expand Up @@ -81,7 +81,7 @@ public function id($object)
}

/**
* Get subject
* Get subject.
*
* Overridden to allow a broader set of valid characters in the ID, and
* if the ID is not a UUID, to call absolutizePath on the ID.
Expand Down Expand Up @@ -128,6 +128,7 @@ public function toString($object)

if (method_exists($object, '__toString') && null !== $object->__toString()) {
$string = (string) $object;

return '' !== $string ? $string : $this->trans('link_add', array(), 'SonataAdminBundle');
}

Expand All @@ -139,4 +140,3 @@ public function toString($object)
return parent::toString($object);
}
}

6 changes: 3 additions & 3 deletions Admin/FieldDescription.php
Expand Up @@ -32,12 +32,12 @@ public function __construct()
public function setAssociationMapping($associationMapping)
{
if (!is_array($associationMapping)) {
throw new \InvalidArgumentException('The association mapping must be an array');
throw new \InvalidArgumentException('The association mapping must be an array');
}

$this->associationMapping = $associationMapping;

if(isset($associationMapping['type'])){
if (isset($associationMapping['type'])) {
$this->type = $this->type ?: $associationMapping['type'];
$this->mappingType = $this->mappingType ?: $associationMapping['type'];
} else {
Expand All @@ -58,7 +58,7 @@ public function getTargetEntity()
return $this->associationMapping['referringDocument'];
}

return null;
return;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions Block/TreeBlockService.php
Expand Up @@ -27,9 +27,9 @@ class TreeBlockService extends BaseBlockService
protected $defaults;

/**
* @param string $name
* @param string $name
* @param EngineInterface $templating
* @param array $defaults
* @param array $defaults
*/
public function __construct($name, EngineInterface $templating, array $defaults = array())
{
Expand Down
20 changes: 9 additions & 11 deletions Builder/DatagridBuilder.php
Expand Up @@ -11,18 +11,16 @@

namespace Sonata\DoctrinePHPCRAdminBundle\Builder;

use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
use Sonata\AdminBundle\Datagrid\Datagrid;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\PagerInterface;
use Sonata\AdminBundle\Filter\FilterFactoryInterface;
use Sonata\AdminBundle\Filter\FilterInterface;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Datagrid\DatagridInterface;
use Sonata\AdminBundle\Datagrid\Datagrid;
use Sonata\AdminBundle\Builder\DatagridBuilderInterface;
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;
use Sonata\AdminBundle\Filter\FilterFactoryInterface;

use Sonata\DoctrinePHPCRAdminBundle\Datagrid\SimplePager;

use Symfony\Component\Form\FormFactory;

class DatagridBuilder implements DatagridBuilderInterface
Expand All @@ -43,7 +41,7 @@ class DatagridBuilder implements DatagridBuilderInterface
protected $guesser;

/**
* Indicates that csrf protection enabled
* Indicates that csrf protection enabled.
*
* @var bool
*/
Expand All @@ -55,10 +53,10 @@ class DatagridBuilder implements DatagridBuilderInterface
protected $pager;

/**
* @param FormFactory $formFactory
* @param FormFactory $formFactory
* @param FilterFactoryInterface $filterFactory
* @param TypeGuesserInterface $guesser
* @param bool $csrfTokenEnabled
* @param TypeGuesserInterface $guesser
* @param bool $csrfTokenEnabled
*/
public function __construct(FormFactory $formFactory, FilterFactoryInterface $filterFactory, TypeGuesserInterface $guesser, $csrfTokenEnabled = true)
{
Expand Down
22 changes: 7 additions & 15 deletions Builder/FormContractor.php
Expand Up @@ -11,15 +11,12 @@

namespace Sonata\DoctrinePHPCRAdminBundle\Builder;

use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\FormContractorInterface;

use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\FormFactoryInterface;

use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;

class FormContractor implements FormContractorInterface
{
/**
Expand All @@ -36,7 +33,7 @@ public function __construct(FormFactoryInterface $formFactory)
}

/**
* The method defines the correct default settings for the provided FieldDescription
* The method defines the correct default settings for the provided FieldDescription.
*
* {@inheritDoc}
*
Expand Down Expand Up @@ -115,7 +112,7 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
if ($type == 'sonata_type_model' || $type == 'sonata_type_model_list') {
if (!$fieldDescription->getTargetEntity()) {
throw new \LogicException(sprintf(
'The field "%s" in class "%s" does not have a target model defined. ' .
'The field "%s" in class "%s" does not have a target model defined. '.
'Please specify the "targetDocument" attribute in the mapping for this class.',
$fieldDescription->getName(),
$fieldDescription->getAdmin()->getClass()
Expand All @@ -124,18 +121,14 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip

$options['class'] = $fieldDescription->getTargetEntity();
$options['model_manager'] = $fieldDescription->getAdmin()->getModelManager();

} else if ($type == 'sonata_type_admin') {

} elseif ($type == 'sonata_type_admin') {
if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}

$options['data_class'] = $fieldDescription->getAssociationAdmin()->getClass();
$fieldDescription->setOption('edit', $fieldDescription->getOption('edit', 'admin'));

} else if ($type == 'sonata_type_collection') {

} elseif ($type == 'sonata_type_collection') {
if (!$fieldDescription->getAssociationAdmin()) {
throw $this->getAssociationAdminException($fieldDescription);
}
Expand All @@ -144,9 +137,8 @@ public function getDefaultOptions($type, FieldDescriptionInterface $fieldDescrip
$options['modifiable'] = true;
$options['type_options'] = array(
'sonata_field_description' => $fieldDescription,
'data_class' => $fieldDescription->getAssociationAdmin()->getClass()
'data_class' => $fieldDescription->getAssociationAdmin()->getClass(),
);

}

return $options;
Expand All @@ -164,7 +156,7 @@ protected function getAssociationAdminException(FieldDescriptionInterface $field
if ($fieldDescription->getTargetEntity()) {
$msg .= " for the target document: `{$fieldDescription->getTargetEntity()}`";
}
$msg .= ", specify the `targetDocument` in the Reference, or the `referringDocument` in the Referrers or use the option `admin_code` to link it.";
$msg .= ', specify the `targetDocument` in the Reference, or the `referringDocument` in the Referrers or use the option `admin_code` to link it.';
} else {
$msg .= ' and use the option `admin_code` to link it.';
}
Expand Down
10 changes: 4 additions & 6 deletions Builder/ListBuilder.php
Expand Up @@ -11,14 +11,13 @@

namespace Sonata\DoctrinePHPCRAdminBundle\Builder;

use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\ListBuilderInterface;
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;

use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;

class ListBuilder implements ListBuilderInterface
{
/**
Expand All @@ -33,7 +32,7 @@ class ListBuilder implements ListBuilderInterface

/**
* @param TypeGuesserInterface $guesser
* @param array $templates
* @param array $templates
*/
public function __construct(TypeGuesserInterface $guesser, array $templates = array())
{
Expand Down Expand Up @@ -83,7 +82,7 @@ public function addField(FieldDescriptionCollection $list, $type = null, FieldDe
private function getTemplate($type)
{
if (!isset($this->templates[$type])) {
return null;
return;
}

return $this->templates[$type];
Expand Down Expand Up @@ -143,7 +142,6 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));

if (!$fieldDescription->getTemplate()) {

$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));

if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
Expand Down
12 changes: 5 additions & 7 deletions Builder/ShowBuilder.php
Expand Up @@ -11,14 +11,13 @@

namespace Sonata\DoctrinePHPCRAdminBundle\Builder;

use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;
use Sonata\AdminBundle\Admin\AdminInterface;
use Sonata\AdminBundle\Admin\FieldDescriptionCollection;
use Sonata\AdminBundle\Admin\FieldDescriptionInterface;
use Sonata\AdminBundle\Builder\ShowBuilderInterface;
use Sonata\AdminBundle\Guesser\TypeGuesserInterface;

use Doctrine\ODM\PHPCR\Mapping\ClassMetadata;

class ShowBuilder implements ShowBuilderInterface
{
/**
Expand Down Expand Up @@ -75,14 +74,14 @@ public function addField(FieldDescriptionCollection $list, $type = null, FieldDe
private function getTemplate($type)
{
if (!isset($this->templates[$type])) {
return null;
return;
}

return $this->templates[$type];
}

/**
* The method defines the correct default settings for the provided FieldDescription
* The method defines the correct default settings for the provided FieldDescription.
*
* {@inheritDoc}
*
Expand Down Expand Up @@ -114,7 +113,6 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
$fieldDescription->setOption('label', $fieldDescription->getOption('label', $fieldDescription->getName()));

if (!$fieldDescription->getTemplate()) {

$fieldDescription->setTemplate($this->getTemplate($fieldDescription->getType()));

if ($fieldDescription->getMappingType() == ClassMetadata::MANY_TO_ONE) {
Expand All @@ -126,7 +124,7 @@ public function fixFieldDescription(AdminInterface $admin, FieldDescriptionInter
}
}

switch($fieldDescription->getMappingType()) {
switch ($fieldDescription->getMappingType()) {
case ClassMetadata::MANY_TO_ONE:
case ClassMetadata::MANY_TO_MANY:
$admin->attachAdminClass($fieldDescription);
Expand Down
53 changes: 53 additions & 0 deletions CONTRIBUTING.md
@@ -0,0 +1,53 @@
Sonata respects the symfony’s conventions about contributing to the code. So before going further please review the [contributing documentation of Symfony](http://symfony.com/doc/current/contributing/code/patches.html#make-a-pull-request).

## Reporting bugs

If you happen to find a bug, we kindly request you to report it. However, before submitting it, please:

* Check the [project documentation available online](https://sonata-project.org/bundles/)

Then, if it appears that it’s a real bug, you may report it using Github by following these 3 points:

* Check if the bug is not already reported!
* A clear title to resume the issue
* A description of the workflow needed to reproduce the bug,

> _NOTE:_ Don’t hesitate giving as much information as you can (OS, PHP version extensions …)
## Pull requests

### Matching coding standards

Before each commit, be sure to match sonata coding standards by running the following command for fix:

```bash
make cs
```

And then, add fixed file to your commit before push.

Be sure to add only **your modified files**. If another files are fixed by cs tools, just revert it before commit.

### Sending a Pull Request

When you send a PR, just make sure that:

* You add valid test cases.
* Tests are green.
* The related documentation is up-to-date.
* You make the PR on the same branch you based your changes on. If you see commits
that you did not make in your PR, you're doing it wrong.
* Also don't forget to add a comment when you update a PR with a ping to the maintainer (``@username``), so he/she will get a notification.

## Contributing to the documentation

You need to install the python tool to check and validate the sphinx syntax:

pip install -r Resources/doc/requirements.txt

and you can check the documentation with the command:

cd Resources/doc/
rm -rf _build && sphinx-build -W -b html -d _build/doctrees . _build/html

The html will be available in the ``_build/html`` folder.

0 comments on commit 0a3f730

Please sign in to comment.