Skip to content

Commit

Permalink
DevKit updates for 3.x branch (#501)
Browse files Browse the repository at this point in the history
* DevKit updates

* Applied fixes from FlintCI (#502)

* DevKit updates
  • Loading branch information
SonataCI authored and kunicmarko20 committed Sep 10, 2018
1 parent 52ebf06 commit bc73939
Show file tree
Hide file tree
Showing 17 changed files with 42 additions and 37 deletions.
7 changes: 4 additions & 3 deletions .travis/before_install_test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env sh
#!/usr/bin/env bash
set -ev

PHP_INI_DIR="$HOME/.phpenv/versions/$(phpenv version-name)/etc/conf.d/"
Expand All @@ -9,5 +9,6 @@ echo "memory_limit=3072M" >> "$TRAVIS_INI_FILE"

sed --in-place "s/\"dev-master\":/\"dev-${TRAVIS_COMMIT}\":/" composer.json

if [ "$SYMFONY" != "" ]; then composer require "symfony/symfony:$SYMFONY" --no-update; fi;
if [ "$SONATA_CORE" != "" ]; then composer require "sonata-project/core-bundle:$SONATA_CORE" --no-update; fi;
if [ "$SYMFONY" != "" ]; then composer require "symfony/symfony:$SYMFONY" --no-update; fi;
if [ "$SONATA_CORE" != "" ]; then composer require "sonata-project/core-bundle:$SONATA_CORE" --no-update; fi;

7 changes: 6 additions & 1 deletion .travis/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ set -ev
mkdir --parents "${HOME}/bin"

# PHPUnit install
wget "https://phar.phpunit.de/phpunit-5.7.phar" --output-document="${HOME}/bin/phpunit"
if [ "${TRAVIS_BRANCH}" = 'master' ]; then
PHPUNIT_VERSION=7
else
PHPUNIT_VERSION=5.7
fi
wget "https://phar.phpunit.de/phpunit-${PHPUNIT_VERSION}.phar" --output-document="${HOME}/bin/phpunit"
chmod u+x "${HOME}/bin/phpunit"

# Coveralls client install
Expand Down
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ It's auto-generated by sonata-project/dev-kit package.
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="tests/bootstrap.php"
>
<testsuites>
Expand Down
10 changes: 5 additions & 5 deletions src/Block/BlockContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function get($meta, array $settings = [])
if (!$meta instanceof BlockInterface) {
$block = $this->blockLoader->load($meta);

if (is_array($meta) && isset($meta['settings'])) {
if (\is_array($meta) && isset($meta['settings'])) {
// merge user settings
$settings = array_merge($meta['settings'], $settings);
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public function get($meta, array $settings = [])
*/
protected function setDefaultSettings(OptionsResolverInterface $optionsResolver, BlockInterface $block)
{
if (__CLASS__ !== get_called_class()) {
if (__CLASS__ !== \get_called_class()) {
@trigger_error(
'The '.__METHOD__.' is deprecated since version 2.3, to be renamed in 4.0.'
.' Use '.__CLASS__.'::configureSettings instead.',
Expand Down Expand Up @@ -259,17 +259,17 @@ private function resolve(BlockInterface $block, $settings)

// Caching method reflection
// NEXT_MAJOR: Remove everything here
$serviceClass = get_class($service);
$serviceClass = \get_class($service);
if (!isset($this->reflectionCache[$serviceClass])) {
$reflector = new \ReflectionMethod($service, 'setDefaultSettings');
$isOldOverwritten = get_class($service) === $reflector->getDeclaringClass()->getName();
$isOldOverwritten = \get_class($service) === $reflector->getDeclaringClass()->getName();

// Prevention for service classes implementing directly the interface and not extends the new base class
if (!method_exists($service, 'configureSettings')) {
$isNewOverwritten = false;
} else {
$reflector = new \ReflectionMethod($service, 'configureSettings');
$isNewOverwritten = get_class($service) === $reflector->getDeclaringClass()->getName();
$isNewOverwritten = \get_class($service) === $reflector->getDeclaringClass()->getName();
}

$this->reflectionCache[$serviceClass] = [
Expand Down
4 changes: 2 additions & 2 deletions src/Block/BlockServiceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function setServices(array $blockServices)
public function getServices()
{
foreach ($this->services as $name => $id) {
if (is_string($id)) {
if (\is_string($id)) {
$this->load($id);
}
}
Expand All @@ -130,7 +130,7 @@ public function getServicesByContext($context, $includeContainers = true)
$containers = $this->container->getParameter('sonata.block.container.types');

foreach ($this->contexts[$context] as $name) {
if (!$includeContainers && in_array($name, $containers)) {
if (!$includeContainers && \in_array($name, $containers)) {
continue;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Block/Loader/ServiceLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ public function __construct(array $types)
*/
public function exists($type)
{
return in_array($type, $this->types, true);
return \in_array($type, $this->types, true);
}

/**
* {@inheritdoc}
*/
public function load($configuration)
{
if (!in_array($configuration['type'], $this->types)) {
if (!\in_array($configuration['type'], $this->types)) {
throw new \RuntimeException(sprintf(
'The block type "%s" does not exist',
$configuration['type']
Expand All @@ -69,7 +69,7 @@ public function load($configuration)
*/
public function support($configuration)
{
if (!is_array($configuration)) {
if (!\is_array($configuration)) {
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Block/Service/MenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function __construct($name, EngineInterface $templating, MenuProviderInte
$this->menuRegistry = $menuRegistry;
} elseif (null === $menuRegistry) {
$this->menuRegistry = new MenuRegistry();
} elseif (is_array($menuRegistry)) { //NEXT_MAJOR: Remove this case
} elseif (\is_array($menuRegistry)) { //NEXT_MAJOR: Remove this case
@trigger_error(
'Initializing '.__CLASS__.' with an array parameter is deprecated since 3.3 and will be removed in 4.0.',
E_USER_DEPRECATED
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Compiler/TweakCompilerPass.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function process(ContainerBuilder $container)
$arguments = $definition->getArguments();

// Replace empty block id with service id
if (empty($arguments) || 0 == strlen($arguments[0])) {
if (empty($arguments) || 0 == \strlen($arguments[0])) {
// NEXT_MAJOR: Remove the condition when Symfony 2.8 support will be dropped.
if (method_exists($definition, 'setArgument')) {
$definition->setArgument(0, $id);
Expand Down Expand Up @@ -89,12 +89,12 @@ public function applyContext(ContainerBuilder $container)
$definition = $container->findDefinition('sonata.block.context_manager');

foreach ($container->getParameter('sonata_block.blocks') as $service => $settings) {
if (count($settings['settings']) > 0) {
if (\count($settings['settings']) > 0) {
$definition->addMethodCall('addSettingsByType', [$service, $settings['settings'], true]);
}
}
foreach ($container->getParameter('sonata_block.blocks_by_class') as $class => $settings) {
if (count($settings['settings']) > 0) {
if (\count($settings['settings']) > 0) {
$definition->addMethodCall('addSettingsByClass', [$class, $settings['settings'], true]);
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@ public function getConfigTreeBuilder()
->validate()
->always(function ($value) {
foreach ($value['blocks'] as $name => &$block) {
if (0 == count($block['contexts'])) {
if (0 == \count($block['contexts'])) {
$block['contexts'] = $value['default_contexts'];
}
}

if (isset($value['profiler']['container_types']) && !empty($value['profiler']['container_types'])
&& isset($value['container']['types']) && !empty($value['container']['types'])
&& 0 !== count(array_diff($value['profiler']['container_types'], $value['container']['types']))) {
&& 0 !== \count(array_diff($value['profiler']['container_types'], $value['container']['types']))) {
throw new \RuntimeException('You cannot have different config options for sonata_block.profiler.container_types and sonata_block.container.types; the first one is deprecated, in case of doubt use the latter');
}

Expand Down Expand Up @@ -165,7 +165,7 @@ public function getConfigTreeBuilder()
->prototype('scalar')->end()
->validate()
->always(function ($value) {
if (count($value) > 0) {
if (\count($value) > 0) {
@trigger_error(
'The menus configuration key is deprecated since 3.3 and will be removed in 4.0.',
E_USER_DEPRECATED
Expand Down
4 changes: 2 additions & 2 deletions src/DependencyInjection/SonataBlockExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public function configureBlockContainers(ContainerBuilder $container, array $con
*/
public function fixConfigurationDeprecation(array &$config)
{
if (count(array_diff($config['profiler']['container_types'], $config['container']['types']))) {
if (\count(array_diff($config['profiler']['container_types'], $config['container']['types']))) {
$config['container']['types'] = array_merge($config['profiler']['container_types'], $config['container']['types']);
}
}
Expand Down Expand Up @@ -188,7 +188,7 @@ public function configureForm(ContainerBuilder $container, array $config)
$contexts = [];

foreach ($config['blocks'] as $service => $settings) {
if (0 == count($settings['contexts'])) {
if (0 == \count($settings['contexts'])) {
$settings['contexts'] = $defaults;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Model/BaseBlock.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,6 @@ public function getTtl()
*/
public function hasChildren()
{
return count($this->children) > 0;
return \count($this->children) > 0;
}
}
6 changes: 3 additions & 3 deletions src/Profiler/DataCollector/BlockDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public function collect(Request $request, Response $response, \Exception $except

// split into containers & real blocks
foreach ($this->blocks as $id => $block) {
if (!is_array($block)) {
if (!\is_array($block)) {
return; // something went wrong while collecting information
}

Expand All @@ -84,7 +84,7 @@ public function collect(Request $request, Response $response, \Exception $except
continue;
}

if (in_array($block['type'], $this->containerTypes)) {
if (\in_array($block['type'], $this->containerTypes)) {
$this->containers[$id] = $block;
} else {
$this->realBlocks[$id] = $block;
Expand All @@ -99,7 +99,7 @@ public function collect(Request $request, Response $response, \Exception $except
*/
public function getTotalBlock()
{
return count($this->realBlocks) + count($this->containers);
return \count($this->realBlocks) + \count($this->containers);
}

/**
Expand Down
8 changes: 4 additions & 4 deletions src/Templating/Helper/BlockHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public function includeJavascripts($media, $basePath = '')
*/
public function includeStylesheets($media, $basePath = '')
{
if (0 === count($this->assets['css'])) {
if (0 === \count($this->assets['css'])) {
return '';
}

Expand Down Expand Up @@ -438,9 +438,9 @@ protected function getEventListeners($eventName)
foreach ($this->eventDispatcher->getListeners($eventName) as $listener) {
if ($listener instanceof \Closure) {
$results[] = '{closure}()';
} elseif (is_object($listener[0])) {
$results[] = get_class($listener[0]);
} elseif (is_string($listener[0])) {
} elseif (\is_object($listener[0])) {
$results[] = \get_class($listener[0]);
} elseif (\is_string($listener[0])) {
$results[] = $listener[0];
} else {
$results[] = 'Unknown type!';
Expand Down
2 changes: 1 addition & 1 deletion src/Util/RecursiveBlockIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RecursiveBlockIterator extends \RecursiveArrayIterator implements \Recursi
*/
public function __construct($array)
{
if (is_object($array)) {
if (\is_object($array)) {
$array = $array->toArray();
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Block/BlockServiceManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testGetBlockService()
$block = $this->createMock('Sonata\BlockBundle\Model\BlockInterface');
$block->expects($this->any())->method('getType')->will($this->returnValue('test'));

$this->assertInstanceOf(get_class($service), $manager->get($block));
$this->assertInstanceOf(\get_class($service), $manager->get($block));
}

public function testInvalidServiceType()
Expand All @@ -49,7 +49,7 @@ public function testInvalidServiceType()
$block = $this->createMock('Sonata\BlockBundle\Model\BlockInterface');
$block->expects($this->any())->method('getType')->will($this->returnValue('test'));

$this->assertInstanceOf(get_class($service), $manager->get($block));
$this->assertInstanceOf(\get_class($service), $manager->get($block));
}

public function testGetBlockServiceException()
Expand Down
2 changes: 1 addition & 1 deletion tests/Exception/Renderer/InlineDebugRendererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public function testRenderWithDebugEnabled()
public function arrayHasKeyValue($key, $value)
{
return new \PHPUnit_Framework_Constraint_Callback(function ($test) use ($key, $value) {
return is_array($test) && array_key_exists($key, $test) && $test[$key] === $value;
return \is_array($test) && array_key_exists($key, $test) && $test[$key] === $value;
});
}
}
2 changes: 1 addition & 1 deletion tests/Twig/Extension/BlockExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,6 @@ public function testFunction($name, $args, $expectedMethod)

$func = $this->env->getFunction($name);
$this->assertInstanceOf('Twig_SimpleFunction', $func);
call_user_func_array($func->getCallable(), $args);
\call_user_func_array($func->getCallable(), $args);
}
}

0 comments on commit bc73939

Please sign in to comment.