Skip to content

Commit

Permalink
Add and apply cs fixer config
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed Feb 17, 2015
1 parent d2f4e6d commit e9ffe96
Show file tree
Hide file tree
Showing 18 changed files with 104 additions and 85 deletions.
20 changes: 20 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

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

return Symfony\CS\Config\Config::create()
->level(Symfony\CS\FixerInterface::PSR2_LEVEL)
->fixers(array(
'concat_with_spaces',
'ordered_use',
'extra_empty_lines',
'phpdoc_params',
'remove_lines_between_uses',
'return',
'unused_use',
'whitespacy_lines',
'short_array_syntax'
))
->finder($finder);
5 changes: 2 additions & 3 deletions src/EventListener/ExceptionConversionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
namespace Jsor\Stack\Hal\EventListener;

use Jsor\Stack\Hal\ExceptionConverter;
use Jsor\Stack\Hal\Response\VndErrorResponse;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\Response;
Expand Down Expand Up @@ -46,8 +45,8 @@ public function onKernelException(GetResponseForExceptionEvent $event)

public static function getSubscribedEvents()
{
return array(
return [
KernelEvents::EXCEPTION => 'onKernelException',
);
];
}
}
4 changes: 2 additions & 2 deletions src/EventListener/RequestFormatValidationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function onKernelRequest(GetResponseEvent $event)

public static function getSubscribedEvents()
{
return array(
return [
KernelEvents::REQUEST => 'onKernelRequest'
);
];
}
}
4 changes: 2 additions & 2 deletions src/EventListener/ResponseConversionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public function onKernelView(GetResponseForControllerResultEvent $event)

public static function getSubscribedEvents()
{
return array(
return [
KernelEvents::VIEW => 'onKernelView'
);
];
}
}
8 changes: 4 additions & 4 deletions src/Exception/ErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ public function __construct(array $errors,

public function getHal()
{
$data = array(
$data = [
'message' => $this->getMessage()
);
];

if ($this->logref) {
$data['@logref'] = $this->logref;
Expand All @@ -43,9 +43,9 @@ private function appendErrors(Hal $hal, array $errors)
{
foreach ($errors as $error) {
if (!is_array($error)) {
$error = array(
$error = [
'message' => (string) $error
);
];
}

$hal->addResource('errors', new Hal(null, $error));
Expand Down
8 changes: 4 additions & 4 deletions src/Exception/FormErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ public function __construct(FormInterface $form,

public function getHal()
{
$data = array(
$data = [
'message' => $this->getMessage()
);
];

if ($this->logref) {
$data['@logref'] = $this->logref;
Expand All @@ -45,9 +45,9 @@ private function appendErrors(Hal $hal, FormInterface $form, $path)
{
/* @var $error FormError */
foreach ($form->getErrors() as $error) {
$data = array(
$data = [
'message' => $error->getMessage()
);
];

$path = rtrim($path, '/');

Expand Down
8 changes: 4 additions & 4 deletions src/Exception/ValidationErrorException.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ public function __construct(ConstraintViolationListInterface $violationList,

public function getHal()
{
$data = array(
$data = [
'message' => $this->getMessage()
);
];

if ($this->logref) {
$data['@logref'] = $this->logref;
Expand All @@ -39,10 +39,10 @@ public function getHal()
$path = str_replace('][', '/', $violation->getPropertyPath());
$path = '/' . trim($path, '[]');

$data = array(
$data = [
'message' => $violation->getMessage(),
'path' => $path
);
];

$hal->addResource('errors', new Hal(null, $data));
}
Expand Down
2 changes: 1 addition & 1 deletion src/ExceptionConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static function logException(LoggerInterface $logger, \Exception $excepti
);

$isCritical = !$exception instanceof HttpExceptionInterface || $exception->getStatusCode() >= 500;
$context = array('exception' => $exception);
$context = ['exception' => $exception];

if ($isCritical) {
$logger->critical($message, $context);
Expand Down
4 changes: 2 additions & 2 deletions src/Response/CreatedResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

class CreatedResponse extends HalResponse
{
public function __construct(Hal $hal, $headers = array(), $prettyPrint = true)
public function __construct(Hal $hal, $headers = [], $prettyPrint = true)
{
parent::__construct($hal, 201, $headers, $prettyPrint);

Expand All @@ -15,7 +15,7 @@ public function __construct(Hal $hal, $headers = array(), $prettyPrint = true)
}
}

public static function create($hal = null, $status = 201, $headers = array(), $prettyPrint = true)
public static function create($hal = null, $status = 201, $headers = [], $prettyPrint = true)
{
return new static($hal, $headers, $prettyPrint);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Response/HalResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class HalResponse extends Response
protected $requestFormat;
protected $prettyPrint;

public function __construct(Hal $hal, $status = 200, $headers = array(), $prettyPrint = true)
public function __construct(Hal $hal, $status = 200, $headers = [], $prettyPrint = true)
{
parent::__construct(null, $status, $headers);

Expand All @@ -23,7 +23,7 @@ public function __construct(Hal $hal, $status = 200, $headers = array(), $pretty
$this->headers->set('Content-Type', 'application/hal+json');
}

public static function create($hal = null, $status = 200, $headers = array(), $prettyPrint = true)
public static function create($hal = null, $status = 200, $headers = [], $prettyPrint = true)
{
return new static($hal, $status, $headers, $prettyPrint);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Response/VndErrorResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@

class VndErrorResponse extends HalResponse
{
public function __construct(Hal $hal, $status = 500, $headers = array(), $prettyPrint = true)
public function __construct(Hal $hal, $status = 500, $headers = [], $prettyPrint = true)
{
parent::__construct($hal, $status, $headers, $prettyPrint);

$this->headers->set('Content-Type', 'application/vnd.error+json');
}

public static function create($hal = null, $status = 500, $headers = array(), $prettyPrint = true)
public static function create($hal = null, $status = 500, $headers = [], $prettyPrint = true)
{
return new static($hal, $status, $headers, $prettyPrint);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/Exception/FormErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ public function it_serializes_exception_to_json()

$form = $formFactory->create(new FormType());

$data = array(
$data = [
'additional' => 'foo'
);
];

$form->submit($data);

Expand Down
8 changes: 4 additions & 4 deletions tests/Exception/ValidationErrorExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ class ValidationErrorExceptionTest extends \PHPUnit_Framework_TestCase
/** @test */
public function it_serializes_exception_to_json()
{
$constraint = new Collection(array(
$constraint = new Collection([
'email' => new Email(),
'name' => new NotBlank(),
'birthday' => new Date(),
));
]);

$data = array(
$data = [
'additional' => 'foo'
);
];

$builder = new ValidatorBuilder();

Expand Down
12 changes: 6 additions & 6 deletions tests/Fixtures/Form/FormType.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ class FormType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('person', new PersonType(), array(
->add('person', new PersonType(), [
'mapped' => false
))
->add('newsletter', 'checkbox', array(
'constraints' => array(
])
->add('newsletter', 'checkbox', [
'constraints' => [
new NotBlank()
),
));
],
]);
}

public function getName()
Expand Down
20 changes: 10 additions & 10 deletions tests/Fixtures/Form/NameType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,20 @@ class NameType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('first_name', 'text', array(
->add('first_name', 'text', [
'mapped' => false,
'constraints' => array(
'constraints' => [
new NotBlank(),
new Length(array('min' => 4)),
),
))
->add('last_name', 'text', array(
new Length(['min' => 4]),
],
])
->add('last_name', 'text', [
'mapped' => false,
'constraints' => array(
'constraints' => [
new NotBlank(),
new Length(array('min' => 4)),
),
));
new Length(['min' => 4]),
],
]);
}

public function getName()
Expand Down
18 changes: 9 additions & 9 deletions tests/Fixtures/Form/PersonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ class PersonType extends AbstractType
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('gender', 'choice', array(
'choices' => array('m' => 'Male', 'f' => 'Female'),
->add('gender', 'choice', [
'choices' => ['m' => 'Male', 'f' => 'Female'],
'mapped' => false,
'constraints' => array(
'constraints' => [
new NotBlank()
),
))
->add('name', new NameType(), array(
],
])
->add('name', new NameType(), [
'mapped' => false,
'constraints' => array(
'constraints' => [
new Valid()
)
));
]
]);
}

public function getName()
Expand Down
26 changes: 13 additions & 13 deletions tests/Negotiation/HalNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ public function it_accepts_hal_headers($acceptHeader, $expected)

public static function provideAcceptHeaders()
{
return array(
array('application/hal+json,application/json;q=0.9,*/*;q=0.8', 'json'),
array('application/json;q=0.9,*/*;q=0.8', 'json'),
array('application/x-json;q=0.9,*/*;q=0.8', 'json'),
return [
['application/hal+json,application/json;q=0.9,*/*;q=0.8', 'json'],
['application/json;q=0.9,*/*;q=0.8', 'json'],
['application/x-json;q=0.9,*/*;q=0.8', 'json'],

array('application/hal+xml,text/xml;q=0.9,*/*;q=0.8', 'xml'),
array('text/xml;q=0.9,*/*;q=0.8', 'xml'),
array('application/xml;q=0.9,*/*;q=0.8', 'xml'),
array('application/x-xml;q=0.9,*/*;q=0.8', 'xml'),
['application/hal+xml,text/xml;q=0.9,*/*;q=0.8', 'xml'],
['text/xml;q=0.9,*/*;q=0.8', 'xml'],
['application/xml;q=0.9,*/*;q=0.8', 'xml'],
['application/x-xml;q=0.9,*/*;q=0.8', 'xml'],

array('text/html, application/json;q=0.8, text/csv;q=0.7', 'html'),
array('text/html', 'html'),
array('text/*, text/html, text/html;level=1, */*', 'html'),
array('text/html; q=0.0', null),
);
['text/html, application/json;q=0.8, text/csv;q=0.7', 'html'],
['text/html', 'html'],
['text/*, text/html, text/html;level=1, */*', 'html'],
['text/html; q=0.0', null],
];
}
}
30 changes: 15 additions & 15 deletions tests/RequestFormatNegotiatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,20 @@ public function it_accepts_hal_headers($acceptHeader, $format)

public static function provideAcceptHeaders()
{
return array(
array('application/hal+json,application/json;q=0.9,*/*;q=0.8', 'json'),
array('application/json;q=0.9,*/*;q=0.8', 'json'),
array('application/x-json;q=0.9,*/*;q=0.8', 'json'),

array('application/hal+xml,text/xml;q=0.9,*/*;q=0.8', 'xml'),
array('text/xml;q=0.9,*/*;q=0.8', 'xml'),
array('application/xml;q=0.9,*/*;q=0.8', 'xml'),
array('application/x-xml;q=0.9,*/*;q=0.8', 'xml'),

array('text/html, application/json;q=0.8, text/csv;q=0.7', 'html'),
array('text/html', 'html'),
array('text/*, text/html, text/html;level=1, */*', 'html'),
array('text/html; q=0.0', 'html'),
);
return [
['application/hal+json,application/json;q=0.9,*/*;q=0.8', 'json'],
['application/json;q=0.9,*/*;q=0.8', 'json'],
['application/x-json;q=0.9,*/*;q=0.8', 'json'],

['application/hal+xml,text/xml;q=0.9,*/*;q=0.8', 'xml'],
['text/xml;q=0.9,*/*;q=0.8', 'xml'],
['application/xml;q=0.9,*/*;q=0.8', 'xml'],
['application/x-xml;q=0.9,*/*;q=0.8', 'xml'],

['text/html, application/json;q=0.8, text/csv;q=0.7', 'html'],
['text/html', 'html'],
['text/*, text/html, text/html;level=1, */*', 'html'],
['text/html; q=0.0', 'html'],
];
}
}

0 comments on commit e9ffe96

Please sign in to comment.