Skip to content

Commit

Permalink
Merge pull request #28 from michalpipa/cs
Browse files Browse the repository at this point in the history
Switch coding standards to PSR-2
  • Loading branch information
lserwatka committed Aug 25, 2015
2 parents fbb455c + f676d17 commit 03c2da4
Show file tree
Hide file tree
Showing 32 changed files with 91 additions and 97 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.idea/
composer.lock
/components/
.php_cs.cache
25 changes: 25 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

return Symfony\CS\Config\Config::create()
->setUsingLinter(false)
->setUsingCache(true)
->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL)
->fixers([
'concat_with_spaces',
'-concat_without_spaces',
'-empty_return',
'-phpdoc_params',
'-phpdoc_separation',
'-phpdoc_to_comment',
'-spaces_cast',
'-blankline_after_open_tag',
'-single_blank_line_before_namespace',
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->exclude([
'vendor',
])
)
;
4 changes: 1 addition & 3 deletions Client/RecommendationClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is part of the EzSystemsRecommendationBundle package
* This file is part of the EzSystemsRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributd with this source code.
Expand All @@ -12,14 +12,12 @@ interface RecommendationClient
/**
* @param mixed $contentId
* @throws \EzSystems\RecommendationBundle\Client\RecommendationClientException If an error occurs with the client
* @return void
*/
public function updateContent($contentId);

/**
* @param mixed $contentId
* @throws \EzSystems\RecommendationBundle\Client\RecommendationClientException If an error occurs with the client
* @return void
*/
public function deleteContent($contentId);
}
32 changes: 16 additions & 16 deletions Client/YooChooseNotifier.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* This file is part of the EzSystemsRecommendationBundle package
* This file is part of the EzSystemsRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributd with this source code.
Expand Down Expand Up @@ -105,11 +105,11 @@ public function updateContent($contentId)
$this->notify(array(array(
'action' => 'update',
'uri' => $this->getContentUri($contentId),
'contentTypeId' => $this->getContentTypeId($contentId)
'contentTypeId' => $this->getContentTypeId($contentId),
)));
} catch (RequestException $e) {
if (isset($this->logger)) {
$this->logger->error("YooChoose Post notification error: ".$e->getMessage());
$this->logger->error('YooChoose Post notification error: ' . $e->getMessage());
}
}
}
Expand All @@ -127,11 +127,11 @@ public function deleteContent($contentId)
$this->notify(array(array(
'action' => 'delete',
'uri' => $this->getContentUri($contentId),
'contentTypeId' => $this->getContentTypeId($contentId)
'contentTypeId' => $this->getContentTypeId($contentId),
)));
} catch (RequestException $e) {
if (isset($this->logger)) {
$this->logger->error("YooChoose Post notification error: ".$e->getMessage());
$this->logger->error('YooChoose Post notification error: ' . $e->getMessage());
}
}
}
Expand All @@ -155,7 +155,7 @@ private function getContentIdentifier($contentId)
}

/**
* Gets ContentType ID based on $contentId
* Gets ContentType ID based on $contentId.
*
* @param mixed $contentId
*
Expand All @@ -174,7 +174,7 @@ protected function getContentTypeId($contentId)
}

/**
* Generates the REST URI of content $contentId
* Generates the REST URI of content $contentId.
*
* @param $contentId
*
Expand Down Expand Up @@ -205,31 +205,31 @@ protected function getContentUri($contentId)
protected function notify(array $events)
{
foreach ($events as $event) {
if (array_keys($event) != array( 'action', 'uri', 'contentTypeId' )) {
if (array_keys($event) != array('action', 'uri', 'contentTypeId')) {
throw new InvalidArgumentException('Invalid action keys');
}
}

if (isset($this->logger)) {
$this->logger->debug("POST notification to YooChoose:".json_encode($events, true));
$this->logger->debug('POST notification to YooChoose:' . json_encode($events, true));
}

$response = $this->guzzle->post(
$this->getNotificationEndpoint(),
array(
'json' => array(
'transaction' => null,
'events' => $events
'events' => $events,
),
'auth' => array(
$this->options['customer-id'],
$this->options['license-key']
)
$this->options['license-key'],
),
)
);

if (isset($this->logger)) {
$this->logger->debug("Got ".$response->getStatusCode()." from YooChoose notification POST");
$this->logger->debug('Got ' . $response->getStatusCode() . ' from YooChoose notification POST');
}
}

Expand All @@ -238,21 +238,21 @@ protected function notify(array $events)
*/
protected function configureOptions(OptionsResolver $resolver)
{
$options = array( 'customer-id', 'license-key', 'api-endpoint', 'server-uri' );
$options = array('customer-id', 'license-key', 'api-endpoint', 'server-uri');
// Could use setDefined() with symfony ~2.6
$resolver->setOptional($options);
$resolver->setDefaults(
array(
'customer-id' => null,
'license-key' => null,
'server-uri' => null,
'api-endpoint' => null
'api-endpoint' => null,
)
);
}

/**
* Returns the yoochoose notification endpoint
* Returns the yoochoose notification endpoint.
*
* @return string
*/
Expand Down
12 changes: 6 additions & 6 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ public function getConfigTreeBuilder()
->arrayNode('yoochoose')
->children()
->scalarNode('customer_id')
->info("YooChoose customer ID")
->example("12345")
->info('YooChoose customer ID')
->example('12345')
->isRequired()
->end()
->scalarNode('license_key')
->info("YooChoose license key")
->example("1234-5678-9012-3456-7890")
->info('YooChoose license key')
->example('1234-5678-9012-3456-7890')
->isRequired()
->end()
->end()
Expand All @@ -39,8 +39,8 @@ public function getConfigTreeBuilder()
->end()
->end()
->scalarNode('server_uri')
->info("HTTP base URI of the eZ Publish server")
->example("http://site.com")
->info('HTTP base URI of the eZ Publish server')
->example('http://site.com')
->isRequired()
->end();

Expand Down
1 change: 0 additions & 1 deletion DependencyInjection/ConfigurationMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* @license For full copyright and license information view LICENSE file distributed with this source code.
* @version //autogentag//
*/

namespace EzSystems\RecommendationBundle\DependencyInjection;

use eZ\Bundle\EzPublishCoreBundle\DependencyInjection\Configuration\SiteAccessAware\ContextualizerInterface;
Expand Down
5 changes: 2 additions & 3 deletions DependencyInjection/EzSystemsRecommendationExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
use Symfony\Component\Config\FileLocator;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\DependencyInjection\Loader;
use EzSystems\RecommendationBundle\DependencyInjection;

/**
* This is the class that loads and manages your bundle configuration
* This is the class that loads and manages your bundle configuration.
*
* To learn more see {@link http://symfony.com/doc/current/cookbook/bundles/extension.html}
*/
Expand All @@ -21,7 +20,7 @@ public function load(array $configs, ContainerBuilder $container)
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));
$loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config'));
$loader->load('services.yml');
$loader->load('slots.yml');
$loader->load('default_settings.yml');
Expand Down
7 changes: 3 additions & 4 deletions EventListener/Login.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the EzSystemsRecommendationBundle package
* This file is part of the EzSystemsRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
Expand Down Expand Up @@ -50,8 +50,7 @@ public function __construct(
GuzzleClient $guzzleClient,
$options = array(),
LoggerInterface $logger = null
)
{
) {
$this->authorizationChecker = $authorizationChecker;
$this->session = $session;
$this->guzzleClient = $guzzleClient;
Expand All @@ -69,7 +68,7 @@ public function onSecurityInteractiveLogin(InteractiveLoginEvent $event)
if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY') | // user has just logged in
$this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { // user has logged in using remember_me cookie

$notificationUri = sprintf($this->getNotificationEndpoint().'%s/%s/%s',
$notificationUri = sprintf($this->getNotificationEndpoint() . '%s/%s/%s',
'login',
$this->session->get('yc-session-id'),
$event->getAuthenticationToken()->getUser()->getAPIUser()->id
Expand Down
2 changes: 1 addition & 1 deletion EventListener/SessionBackup.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the EzSystemsRecommendationBundle package
* This file is part of the EzSystemsRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the EzSystemsRecommendationBundle package
* This file is part of the EzSystemsRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
Expand Down
3 changes: 1 addition & 2 deletions EzSystemsRecommendationBundle.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php
/**
* This file is part of the EzSystemRecommendationBundle package
* This file is part of the EzSystemRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributd with this source code.
*/

namespace EzSystems\RecommendationBundle;

use EzSystems\RecommendationBundle\DependencyInjection\EzSystemsRecommendationExtension;
Expand Down
8 changes: 3 additions & 5 deletions Tests/Client/YooChooseNotifierTest.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php
/**
* This file is part of the eZ Publish Kernel package
* This file is part of the eZ Publish Kernel package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributd with this source code.
*/

namespace EzSystems\RecommendationBundle\Tests\Client;

use EzSystems\RecommendationBundle\Client\YooChooseNotifier;
use Guzzle\Http\Message\Response;
use GuzzleHttp\ClientInterface;
use PHPUnit_Framework_TestCase;

class YooChooseNotifierTest extends PHPUnit_Framework_TestCase
Expand Down Expand Up @@ -54,15 +52,15 @@ protected function getNotificationBody($action, $contentId)
'events' => array(
array(
'action' => $action,
'uri' => 'http://example.com/api/ezp/v2/content/objects/'.$contentId,
'uri' => 'http://example.com/api/ezp/v2/content/objects/' . $contentId,
),
),
),
);
}

/**
* Returns the expected API endpoint for notifications
* Returns the expected API endpoint for notifications.
* @return string
*/
protected function getExpectedEndpoint()
Expand Down
15 changes: 7 additions & 8 deletions Twig/RecommendationTwigExtension.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php

/**
* This file is part of the EzSystemsRecommendationBundle package
* This file is part of the EzSystemsRecommendationBundle package.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
Expand Down Expand Up @@ -130,13 +130,13 @@ public function getFunctions()
return array(
new Twig_SimpleFunction('yc_show_recommendations', array($this, 'showRecommendations'), array(
'is_safe' => array('html'),
'needs_environment' => true
'needs_environment' => true,
)),

new Twig_SimpleFunction('yc_track_user', array($this, 'trackUser'), array(
'is_safe' => array('html'),
'needs_environment' => true
))
'needs_environment' => true,
)),
);
}

Expand All @@ -149,8 +149,7 @@ public function getFunctions()
*/
public function trackUser(Twig_Environment $twigEnvironment, $contentId)
{
if (!in_array($this->getContentIdentifier($contentId), $this->options['includedContentTypes']))
{
if (!in_array($this->getContentIdentifier($contentId), $this->options['includedContentTypes'])) {
return '';
}

Expand All @@ -163,7 +162,7 @@ public function trackUser(Twig_Environment $twigEnvironment, $contentId)
'userId' => $this->getCurrentUserId(),
'customerId' => $this->options['customerId'],
'consumeTimeout' => ($this->options['consumeTimeout'] * 1000),
'trackingScriptUrl' => $this->options['trackingScriptUrl']
'trackingScriptUrl' => $this->options['trackingScriptUrl'],
)
);
}
Expand Down Expand Up @@ -241,7 +240,7 @@ public function showRecommendations(
'feedbackUrl' => $this->getFeedbackUrl($this->getContentTypeId($contentType)),
'contentType' => $this->getContentTypeId($this->getContentIdentifier($contentId)),
'outputTypeId' => $this->getContentTypeId($contentType),
'categoryPath' => $this->getLocationPathString($contentId)
'categoryPath' => $this->getLocationPathString($contentId),
)
);
}
Expand Down
Loading

0 comments on commit 03c2da4

Please sign in to comment.