Skip to content

Commit

Permalink
Merge pull request #18 from ezsystems/psr2
Browse files Browse the repository at this point in the history
Fix EZP-24612: Switch CS to PSR-2
  • Loading branch information
lolautruche committed Jul 22, 2015
2 parents ace50c4 + d0fad81 commit d79f74a
Show file tree
Hide file tree
Showing 24 changed files with 575 additions and 504 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
vendor
composer.lock
.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',
])
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->exclude([
'ezpublish_legacy',
'vendor',
])
)
;
82 changes: 43 additions & 39 deletions Comments/CommentsRenderer.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* File containing the CommentsRenderer class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/

Expand Down Expand Up @@ -46,19 +48,19 @@ class CommentsRenderer implements ProviderInterface, ContentAuthorizerInterface
* @param ProviderInterface[] Comments providers, indexed by their label.
* @param string|null $defaultProvider Label of provider to use by default. If not provided, the first entry in $providers will be used.
*/
public function __construct( MatcherFactoryInterface $matcherFactory, ConfigResolverInterface $configResolver, array $providers = array(), $defaultProvider = null )
public function __construct(MatcherFactoryInterface $matcherFactory, ConfigResolverInterface $configResolver, array $providers = array(), $defaultProvider = null)
{
$this->matcherFactory = $matcherFactory;
$this->providers = $providers;
$this->setDefaultProviderLabel(
$defaultProvider ?: $configResolver->getParameter( 'default_provider', 'ez_comments' )
$defaultProvider ?: $configResolver->getParameter('default_provider', 'ez_comments')
);
}

/**
* @param LoggerInterface $logger
*/
public function setLogger( LoggerInterface $logger )
public function setLogger(LoggerInterface $logger)
{
$this->logger = $logger;
}
Expand All @@ -68,7 +70,7 @@ public function setLogger( LoggerInterface $logger )
*
* @param string $defaultProvider Label of the provider to use.
*/
public function setDefaultProviderLabel( $defaultProvider )
public function setDefaultProviderLabel($defaultProvider)
{
$this->defaultProvider = $defaultProvider;
}
Expand All @@ -91,20 +93,20 @@ public function getDefaultProviderLabel()
*/
public function getDefaultProvider()
{
if ( isset( $this->defaultProvider ) )
{
return $this->getProvider( $this->defaultProvider );
if (isset($this->defaultProvider)) {
return $this->getProvider($this->defaultProvider);
}

$providerLabels = array_keys( $this->providers );
$providerLabels = array_keys($this->providers);

return $this->providers[$providerLabels[0]];
}

/**
* @param ProviderInterface $provider
* @param string $label
*/
public function addProvider( ProviderInterface $provider, $label )
public function addProvider(ProviderInterface $provider, $label)
{
$this->providers[$label] = $provider;
}
Expand All @@ -114,32 +116,31 @@ public function addProvider( ProviderInterface $provider, $label )
*
* @return bool
*/
public function hasProvider( $label )
public function hasProvider($label)
{
return isset( $this->providers[$label] );
return isset($this->providers[$label]);
}

/**
* Retrieves a comments provider by its label
* Retrieves a comments provider by its label.
*
* @param $label
*
* @return ProviderInterface
*
* @throws \InvalidArgumentException
*/
public function getProvider( $label )
public function getProvider($label)
{
if ( !isset( $this->providers[$label] ) )
{
throw new InvalidArgumentException( "Unknown comments provider '$label'" );
if (!isset($this->providers[$label])) {
throw new InvalidArgumentException("Unknown comments provider '$label'");
}

return $this->providers[$label];
}

/**
* Returns all available providers
* Returns all available providers.
*
* @return ProviderInterface[]
*/
Expand All @@ -159,31 +160,31 @@ public function getAllProviders()
*
* @return string
*/
public function render( Request $request, array $options = array() )
public function render(Request $request, array $options = array())
{
$provider = isset( $options['provider'] ) ? $this->getProvider( $options['provider'] ) : $this->getDefaultProvider();
unset( $options['provider'] );
$provider = isset($options['provider']) ? $this->getProvider($options['provider']) : $this->getDefaultProvider();
unset($options['provider']);

return $provider->render( $request, $options );
return $provider->render($request, $options);
}

/**
* Renders the comments list for a given content.
* Comment form might also be included
* Comment form might also be included.
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
* @param \Symfony\Component\HttpFoundation\Request $request
* @param array $options
*
* @return mixed
*/
public function renderForContent( ContentInfo $contentInfo, Request $request, array $options = array() )
public function renderForContent(ContentInfo $contentInfo, Request $request, array $options = array())
{
$commentsConfig = $this->getCommentsConfig( $contentInfo );
if ( isset( $commentsConfig['enabled'] ) && $commentsConfig['enabled'] === false )
{
if ( $this->logger )
$this->logger->debug( "Commenting is specifically disabled for content #$contentInfo->id" );
$commentsConfig = $this->getCommentsConfig($contentInfo);
if (isset($commentsConfig['enabled']) && $commentsConfig['enabled'] === false) {
if ($this->logger) {
$this->logger->debug("Commenting is specifically disabled for content #$contentInfo->id");
}

return;
}
Expand All @@ -195,17 +196,19 @@ public function renderForContent( ContentInfo $contentInfo, Request $request, ar
* 3. Defaut provider.
*/
$providerLabel = $this->defaultProvider;
if ( isset( $options['provider'] ) )
if (isset($options['provider'])) {
$providerLabel = $options['provider'];
else if ( isset( $commentsConfig['provider'] ) )
} elseif (isset($commentsConfig['provider'])) {
$providerLabel = $commentsConfig['provider'];
$provider = $this->getProvider( $providerLabel );
unset( $options['provider'] );
}
$provider = $this->getProvider($providerLabel);
unset($options['provider']);

// Merge configured options with explicitly passed options.
// Explicit options always have precedence.
$options = isset( $commentsConfig['options'] ) ? $options + $commentsConfig['options'] : $options;
return $provider->renderForContent( $contentInfo, $request, $options );
$options = isset($commentsConfig['options']) ? $options + $commentsConfig['options'] : $options;

return $provider->renderForContent($contentInfo, $request, $options);
}

/**
Expand All @@ -215,10 +218,11 @@ public function renderForContent( ContentInfo $contentInfo, Request $request, ar
*
* @return bool
*/
public function canCommentContent( ContentInfo $contentInfo )
public function canCommentContent(ContentInfo $contentInfo)
{
$commentConfig = $this->getCommentsConfig( $contentInfo );
return !empty( $commentConfig['enabled'] );
$commentConfig = $this->getCommentsConfig($contentInfo);

return !empty($commentConfig['enabled']);
}

/**
Expand All @@ -228,8 +232,8 @@ public function canCommentContent( ContentInfo $contentInfo )
*
* @return array|null
*/
private function getCommentsConfig( ContentInfo $contentInfo )
private function getCommentsConfig(ContentInfo $contentInfo)
{
return $this->matcherFactory->match( $contentInfo, 'comments' );
return $this->matcherFactory->match($contentInfo, 'comments');
}
}
4 changes: 3 additions & 1 deletion Comments/ContentAuthorizerInterface.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* File containing the AuthorizerInterface class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/

Expand All @@ -24,5 +26,5 @@ interface ContentAuthorizerInterface
*
* @return bool
*/
public function canCommentContent( ContentInfo $contentInfo );
public function canCommentContent(ContentInfo $contentInfo);
}
8 changes: 5 additions & 3 deletions Comments/Provider/DisqusProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* File containing the Disqus comments provider class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/

Expand All @@ -21,7 +23,7 @@ class DisqusProvider extends TemplateBasedProvider
*/
protected $shortName;

public function setShortName( $shortName )
public function setShortName($shortName)
{
$this->shortName = $shortName;
}
Expand All @@ -35,7 +37,7 @@ public function setShortName( $shortName )
*
* @return string
*/
public function render( Request $request, array $options = array() )
public function render(Request $request, array $options = array())
{
return $this->doRender(
$options + array(
Expand All @@ -55,7 +57,7 @@ public function render( Request $request, array $options = array() )
*
* @return mixed
*/
public function renderForContent( ContentInfo $contentInfo, Request $request, array $options = array() )
public function renderForContent(ContentInfo $contentInfo, Request $request, array $options = array())
{
return $this->doRender(
$options + array(
Expand Down
26 changes: 14 additions & 12 deletions Comments/Provider/FacebookProvider.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

/**
* File containing the FacebookProvider comments provider class.
*
* @copyright Copyright (C) eZ Systems AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*
* @version //autogentag//
*/

Expand Down Expand Up @@ -69,17 +71,17 @@ class FacebookProvider extends TemplateBasedProvider
*/
private $router;

public function __construct( $appId, array $defaultOptions, LocationService $locationService, RouterInterface $router, EngineInterface $templateEngine = null, $defaultTemplate = null )
public function __construct($appId, array $defaultOptions, LocationService $locationService, RouterInterface $router, EngineInterface $templateEngine = null, $defaultTemplate = null)
{
$this->appId = $appId;
$this->defaultWidth = isset( $defaultOptions['width'] ) ? $defaultOptions['width'] : static::DEFAULT_WIDTH;
$this->defaultNumPosts = isset( $defaultOptions['num_posts'] ) ? $defaultOptions['num_posts'] : static::DEFAULT_NUM_POSTS;
$this->defaultColorScheme = isset( $defaultOptions['color_scheme'] ) ? $defaultOptions['color_scheme'] : static::DEFAULT_COLOR_SCHEME;
$this->defaultIncludeSDK = isset( $defaultOptions['include_sdk'] ) ? $defaultOptions['include_sdk'] : static::DEFAULT_INCLUDE_SDK;
$this->defaultWidth = isset($defaultOptions['width']) ? $defaultOptions['width'] : static::DEFAULT_WIDTH;
$this->defaultNumPosts = isset($defaultOptions['num_posts']) ? $defaultOptions['num_posts'] : static::DEFAULT_NUM_POSTS;
$this->defaultColorScheme = isset($defaultOptions['color_scheme']) ? $defaultOptions['color_scheme'] : static::DEFAULT_COLOR_SCHEME;
$this->defaultIncludeSDK = isset($defaultOptions['include_sdk']) ? $defaultOptions['include_sdk'] : static::DEFAULT_INCLUDE_SDK;
$this->locationService = $locationService;
$this->router = $router;

parent::__construct( $templateEngine, $defaultTemplate );
parent::__construct($templateEngine, $defaultTemplate);
}

/**
Expand All @@ -91,7 +93,7 @@ public function __construct( $appId, array $defaultOptions, LocationService $loc
*
* @return string
*/
public function render( Request $request, array $options = array() )
public function render(Request $request, array $options = array())
{
return $this->doRender(
$options + array(
Expand All @@ -100,24 +102,24 @@ public function render( Request $request, array $options = array() )
'num_posts' => $this->defaultNumPosts,
'color_scheme' => $this->defaultColorScheme,
'include_sdk' => $this->defaultIncludeSDK,
'url' => $request->getSchemeAndHttpHost() . $request->attributes->get( 'semanticPathinfo', $request->getPathInfo() )
'url' => $request->getSchemeAndHttpHost() . $request->attributes->get('semanticPathinfo', $request->getPathInfo()),
)
);
}

/**
* Renders the comments list for a given content.
* Comment form might also be included
* Comment form might also be included.
*
* @param \eZ\Publish\API\Repository\Values\Content\ContentInfo $contentInfo
* @param \Symfony\Component\HttpFoundation\Request $request
* @param array $options
*
* @return string
*/
public function renderForContent( ContentInfo $contentInfo, Request $request, array $options = array() )
public function renderForContent(ContentInfo $contentInfo, Request $request, array $options = array())
{
$foo = $this->locationService->loadLocation( $contentInfo->mainLocationId );
$foo = $this->locationService->loadLocation($contentInfo->mainLocationId);

return $this->doRender(
$options + array(
Expand All @@ -126,7 +128,7 @@ public function renderForContent( ContentInfo $contentInfo, Request $request, ar
'num_posts' => $this->defaultNumPosts,
'color_scheme' => $this->defaultColorScheme,
'include_sdk' => $this->defaultIncludeSDK,
'url' => $this->router->generate( $foo, array(), true )
'url' => $this->router->generate($foo, array(), true),
)
);
}
Expand Down
Loading

0 comments on commit d79f74a

Please sign in to comment.