Skip to content

Commit

Permalink
Merge pull request #144 from pborreli/analysis-8A3WGV
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
pborreli authored Apr 17, 2017
2 parents 0216aba + a93de75 commit f294b9e
Show file tree
Hide file tree
Showing 18 changed files with 91 additions and 93 deletions.
4 changes: 2 additions & 2 deletions app/AppKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = array(
$bundles = [
new Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
new Symfony\Bundle\SecurityBundle\SecurityBundle(),
new Symfony\Bundle\TwigBundle\TwigBundle(),
Expand All @@ -25,7 +25,7 @@ public function registerBundles()
new Liip\MonitorBundle\LiipMonitorBundle(),

new Evolution7\BugsnagBundle\BugsnagBundle(),
);
];

if ('dev' === $this->getEnvironment()) {
$bundles[] = new Symfony\Bundle\WebProfilerBundle\WebProfilerBundle();
Expand Down
15 changes: 7 additions & 8 deletions app/SymfonyRequirements.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ public function __construct($cfgName, $evaluation, $approveCfgAbsence = false, $
*/
class RequirementCollection implements IteratorAggregate
{
private $requirements = array();
private $requirements = [];

/**
* Gets the current RequirementCollection as an Iterator.
Expand Down Expand Up @@ -279,7 +279,7 @@ public function all()
*/
public function getRequirements()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if (!$req->isOptional()) {
$array[] = $req;
Expand All @@ -296,7 +296,7 @@ public function getRequirements()
*/
public function getFailedRequirements()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && !$req->isOptional()) {
$array[] = $req;
Expand All @@ -313,7 +313,7 @@ public function getFailedRequirements()
*/
public function getRecommendations()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if ($req->isOptional()) {
$array[] = $req;
Expand All @@ -330,7 +330,7 @@ public function getRecommendations()
*/
public function getFailedRecommendations()
{
$array = array();
$array = [];
foreach ($this->requirements as $req) {
if (!$req->isFulfilled() && $req->isOptional()) {
$array[] = $req;
Expand Down Expand Up @@ -434,7 +434,7 @@ public function __construct()
}

if (version_compare($installedPhpVersion, self::REQUIRED_PHP_VERSION, '>=')) {
$timezones = array();
$timezones = [];
foreach (DateTimeZone::listAbbreviations() as $abbreviations) {
foreach ($abbreviations as $abbreviation) {
$timezones[$abbreviation['timezone_id']] = true;
Expand Down Expand Up @@ -707,8 +707,7 @@ function_exists('posix_isatty'),
||
(extension_loaded('xcache') && ini_get('xcache.cacher'))
||
(extension_loaded('wincache') && ini_get('wincache.ocenabled'))
;
(extension_loaded('wincache') && ini_get('wincache.ocenabled'));

$this->addRecommendation(
$accelerator,
Expand Down
2 changes: 1 addition & 1 deletion app/autoload.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,6 @@
*/
$loader = require __DIR__.'/../vendor/autoload.php';

AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
AnnotationRegistry::registerLoader([$loader, 'loadClass']);

return $loader;
18 changes: 9 additions & 9 deletions app/check.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

echo '> Checking Symfony requirements:'.PHP_EOL.' ';

$messages = array();
$messages = [];
foreach ($symfonyRequirements->getRequirements() as $req) {
/** @var $req Requirement */
if ($helpText = get_error_message($req, $lineSize)) {
Expand Down Expand Up @@ -99,15 +99,15 @@ function echo_title($title, $style = null)
function echo_style($style, $message)
{
// ANSI color codes
$styles = array(
'reset' => "\033[0m",
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m",
'error' => "\033[37;41m",
$styles = [
'reset' => "\033[0m",
'red' => "\033[31m",
'green' => "\033[32m",
'yellow' => "\033[33m",
'error' => "\033[37;41m",
'success' => "\033[37;42m",
'title' => "\033[34m",
);
'title' => "\033[34m",
];
$supports = has_color_support();

echo($supports ? $styles[$style] : '').$message.($supports ? $styles['reset'] : '');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function it_return_zero_status_if_no_vulnerabilities_found(
$pusher->trigger(
['new_channel'],
'consumer:new-step',
array('message' => 'Checking vulnerability')
['message' => 'Checking vulnerability']
)->shouldBeCalled();

$securityChecker->check(sys_get_temp_dir().'/composer_dir/composer.lock')
Expand All @@ -64,7 +64,7 @@ public function it_push_error_message_when_error_occurs_during_vulnerability_che
$pusher->trigger(
['new_channel'],
'consumer:new-step',
array('message' => 'Checking vulnerability')
['message' => 'Checking vulnerability']
)->shouldBeCalled();

$securityChecker->check(sys_get_temp_dir().'/composer_dir/composer.lock')
Expand All @@ -73,7 +73,7 @@ public function it_push_error_message_when_error_occurs_during_vulnerability_che
$pusher->trigger(
['new_channel'],
'consumer:error',
array('message' => 'Error!')
['message' => 'Error!']
)->shouldBeCalled();

$this->execute($event, 'composer_dir')->shouldReturn(1);
Expand All @@ -91,7 +91,7 @@ public function it_push_error_message_and_alerts_when_vulnerability_found(
$pusher->trigger(
['new_channel'],
'consumer:new-step',
array('message' => 'Checking vulnerability')
['message' => 'Checking vulnerability']
)->shouldBeCalled();

$securityChecker
Expand All @@ -103,17 +103,17 @@ public function it_push_error_message_and_alerts_when_vulnerability_found(
$pusher->trigger(
['new_channel'],
'consumer:step-error',
array(
[
'message' => 'Vulnerability found : 1',
)
]
)->shouldBeCalled();

$pusher->trigger(
['new_channel'],
'consumer:vulnerabilities',
array(
[
'message' => $this->getVulnerabilityMessage(),
)
]
)->shouldBeCalled();

$this->execute($event, 'composer_dir')->shouldReturn(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function it_dump_composer_json_content_to_file(
$message->getValue('channelName')->shouldBeCalled()->willReturn('new_channel');
$message->getValue('body')->shouldBeCalled()->willReturn('composer.json content');

$pusher->trigger(['new_channel'], 'consumer:new-step', array('message' => 'Starting async job'))
$pusher->trigger(['new_channel'], 'consumer:new-step', ['message' => 'Starting async job'])
->shouldBeCalled();
$filesystem->mkdir(sys_get_temp_dir().'/'.'composer_dir')->shouldBeCalled();
$filesystem->dumpFile(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class UploadComposerConsumerSpec extends ObjectBehavior
{
public function it_is_consumer()
{
$this->beConstructedWith(array());
$this->beConstructedWith([]);
$this->shouldBeAnInstanceOf('Sonata\NotificationBundle\Consumer\ConsumerInterface');
}

Expand All @@ -29,9 +29,9 @@ public function it_execute_all_steps_and_return_0_status_code(
StepInterface $step1,
StepInterface $step2
) {
$this->beConstructedWith(array(
$this->beConstructedWith([
$step1, $step2,
));
]);

$step1->execute($event, Argument::type('string'))->shouldBeCalled()->willReturn(0);
$step2->execute($event, Argument::type('string'))->shouldBeCalled()->willReturn(0);
Expand All @@ -44,9 +44,9 @@ public function it_interrupt_the_execution_of_steps_when_any_of_them_return_non_
StepInterface $step1,
StepInterface $step2
) {
$this->beConstructedWith(array(
$this->beConstructedWith([
$step1, $step2,
));
]);

$step1->execute($event, Argument::type('string'))->shouldBeCalled()->willReturn(5);
$step2->execute(Argument::any(), Argument::any())->shouldNotBeCalled();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function it_render_welcome_page(

$templating->renderResponse(
'AyalineComposerBundle:Composer:index.html.twig',
array('form' => $formView)
['form' => $formView]
)->shouldBeCalled()->willReturn($response);

$this->indexAction()->shouldReturn($response);
Expand All @@ -58,11 +58,11 @@ public function it_return_json_with_error_message_when_form_data_is_not_valid_js
$composerForm->isValid()->shouldBeCalled()->willReturn(false);

$composerForm->get('body')->shouldBeCalled()->willReturn($composerForm);
$composerForm->getErrors()->shouldBeCalled()->willReturn(array($composerFormError));
$composerForm->getErrors()->shouldBeCalled()->willReturn([$composerFormError]);
$composerFormError->getMessage()->shouldBeCalled()->willReturn('Please provide a composer.json');

$this->uploadComposerAction($request)->shouldBeJsonResponse(
array('status' => 'ko', 'message' => array('Please provide a composer.json'))
['status' => 'ko', 'message' => ['Please provide a composer.json']]
);
}

Expand All @@ -82,28 +82,28 @@ public function it_return_json_with_success_status_and_create_sonata_notificatio

$composerForm->handleRequest($request)->shouldBeCalled();
$composerForm->isValid()->shouldBeCalled()->willReturn(true);
$composerForm->getData()->shouldBeCalled()->willReturn(array(
'body' => $composerJsonContent,
$composerForm->getData()->shouldBeCalled()->willReturn([
'body' => $composerJsonContent,
'hasDevDependencies' => false,
));
]);

$request->getSession()->shouldBeCalled()->willReturn($session);
$session->get('channelName')->shouldBeCalled()->willReturn('example_channel_name');

$sonataNotificationsBackend->createAndPublish('upload.composer', array(
'body' => $composerJsonContent,
'channelName' => 'example_channel_name',
$sonataNotificationsBackend->createAndPublish('upload.composer', [
'body' => $composerJsonContent,
'channelName' => 'example_channel_name',
'hasDevDependencies' => false,
))->shouldBeCalled();
])->shouldBeCalled();

$this->uploadComposerAction($request)->shouldBeJsonResponse(
array('status' => 'ok')
['status' => 'ok']
);
}

public function getMatchers()
{
return array(
return [
'beJsonResponse' => function ($response, $data) {
if (!$response instanceof JsonResponse) {
return false;
Expand All @@ -114,6 +114,6 @@ public function getMatchers()
JSON_HEX_TAG | JSON_HEX_APOS | JSON_HEX_AMP | JSON_HEX_QUOT
);
},
);
];
}
}
22 changes: 11 additions & 11 deletions spec/Ayaline/Bundle/ComposerBundle/Form/Type/ComposerTypeSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,24 @@ public function it_add_fields_during_build_form(FormBuilder $builder)
$builder->add(
'body',
\Symfony\Component\Form\Extension\Core\Type\TextareaType::class,
array(
'attr' => array(
'class' => 'form-control',
'rows' => 15,
[
'attr' => [
'class' => 'form-control',
'rows' => 15,
'spellcheck' => false,
),
'data' => $this->getDefaultComposerBody(),
'constraints' => array(
],
'data' => $this->getDefaultComposerBody(),
'constraints' => [
new ComposerJson(),
),
)
],
]
)->shouldBeCalled()->willReturn($builder);

$builder->add('hasDevDependencies', \Symfony\Component\Form\Extension\Core\Type\CheckboxType::class, array('required' => true))
$builder->add('hasDevDependencies', \Symfony\Component\Form\Extension\Core\Type\CheckboxType::class, ['required' => true])
->shouldBeCalled()
->willReturn($builder);

$this->buildForm($builder, array());
$this->buildForm($builder, []);
}

private function getDefaultComposerBody()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,20 @@ public function __construct(SecurityChecker $securityChecker)
*/
public function execute(ConsumerEvent $event, $directory)
{
$this->triggerNewStep($event, array('message' => 'Checking vulnerability'));
$this->triggerNewStep($event, ['message' => 'Checking vulnerability']);

try {
$alerts = $this->securityChecker->check($this->workingTempPath.'/'.$directory.'/composer.lock');
} catch (\RuntimeException $e) {
$this->triggerError($event, array('message' => $e->getMessage()));
$this->triggerError($event, ['message' => $e->getMessage()]);

return 1;
}

$vulnerabilityCount = $this->securityChecker->getLastVulnerabilityCount();
if ($vulnerabilityCount > 0) {
$this->triggerStepError($event, array('message' => 'Vulnerability found : '.$vulnerabilityCount));
$this->triggerVulnerabilities($event, array('message' => json_encode($alerts)));
$this->triggerStepError($event, ['message' => 'Vulnerability found : '.$vulnerabilityCount]);
$this->triggerVulnerabilities($event, ['message' => json_encode($alerts)]);
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function execute(ConsumerEvent $event, $directory)

$process = $this->runProcess(sprintf('%s show --installed', $this->composerBinPath), $workingDirectory, $output);
if ($process->isSuccessful()) {
$this->triggerComposerInstalled($event, array('message' => $process->getOutput()));
$this->triggerComposerInstalled($event, ['message' => $process->getOutput()]);
}

return 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class ComposerUpdateStep extends AbstractStep
*/
public function execute(ConsumerEvent $event, $directory)
{
$this->triggerNewStep($event, array('message' => './composer update'));
$this->triggerNewStep($event, ['message' => './composer update']);

$output = null;
$workingDirectory = $this->workingTempPath.'/'.$directory;
Expand All @@ -37,20 +37,20 @@ public function execute(ConsumerEvent $event, $directory)
$process = $this->runProcess($commandLine, $workingDirectory, $output);

if (!$process->isSuccessful()) {
$this->triggerError($event, array('message' => nl2br($output)));
$this->triggerStepError($event, array('message' => 'Composer failed'));
$this->triggerError($event, ['message' => nl2br($output)]);
$this->triggerStepError($event, ['message' => 'Composer failed']);

return 1;
}

if (!is_dir($this->workingTempPath.'/'.$directory.'/vendor')
|| !is_file($this->workingTempPath.'/'.$directory.'/composer.lock')) {
$this->triggerStepError($event, array('message' => 'Fatal error during composer update'));
$this->triggerStepError($event, ['message' => 'Fatal error during composer update']);

return 1;
}

$this->triggerComposerOutput($event, array('message' => $process->getOutput()));
$this->triggerComposerOutput($event, ['message' => $process->getOutput()]);

return 0;
}
Expand Down
Loading

0 comments on commit f294b9e

Please sign in to comment.