Skip to content

Commit

Permalink
Merge branch '3.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
jlamur committed Nov 2, 2017
2 parents 9e7f318 + 2c61a87 commit 4ddee87
Show file tree
Hide file tree
Showing 15 changed files with 111 additions and 40 deletions.
2 changes: 2 additions & 0 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@

```
$ composer show --latest 'sonata-project/*'
# Put the result here.
```

#### Symfony packages

```
$ composer show --latest 'symfony/*'
# Put the result here.
```

#### PHP version
Expand Down
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ php:
- nightly

sudo: false
dist: precise
dist: trusty

cache:
pip: true
Expand Down Expand Up @@ -53,7 +53,6 @@ matrix:
- php: '7.1'
env: SYMFONY_DEPRECATIONS_HELPER=0
- php: hhvm
dist: trusty
allow_failures:
- php: nightly
- php: hhvm
Expand Down
4 changes: 3 additions & 1 deletion .travis/install_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ chmod u+x "${HOME}/bin/coveralls"
# To be removed when these issues are resolved:
# https://github.com/composer/composer/issues/5355
# https://github.com/composer/composer/issues/5030
composer update --prefer-dist --no-interaction --prefer-stable --quiet --ignore-platform-reqs
if [ "${COMPOSER_FLAGS}" = '--prefer-lowest' ]; then
composer update --prefer-dist --no-interaction --prefer-stable --quiet --ignore-platform-reqs
fi

composer update --prefer-dist --no-interaction --prefer-stable ${COMPOSER_FLAGS}
4 changes: 2 additions & 2 deletions Block/BlockContextManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,14 @@ private function resolve(BlockInterface $block, $settings)
$serviceClass = get_class($service);
if (!isset($this->reflectionCache[$serviceClass])) {
$reflector = new \ReflectionMethod($service, 'setDefaultSettings');
$isOldOverwritten = $reflector->getDeclaringClass()->getName() !== 'Sonata\BlockBundle\Block\AbstractBlockService';
$isOldOverwritten = 'Sonata\BlockBundle\Block\AbstractBlockService' !== $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 = $reflector->getDeclaringClass()->getName() !== 'Sonata\BlockBundle\Block\AbstractBlockService';
$isNewOverwritten = 'Sonata\BlockBundle\Block\AbstractBlockService' !== $reflector->getDeclaringClass()->getName();
}

$this->reflectionCache[$serviceClass] = [
Expand Down
2 changes: 1 addition & 1 deletion Block/Service/ContainerBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function getBlockMetadata($code = null)
protected function getDecorator($layout)
{
$key = '{{ CONTENT }}';
if (strpos($layout, $key) === false) {
if (false === strpos($layout, $key)) {
return [];
}

Expand Down
8 changes: 4 additions & 4 deletions Block/Service/MenuBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class MenuBlockService extends AbstractAdminBlockService
*
* @var array
*
* @deprecated since 3.x, to be removed in 4.0
* @deprecated since 3.3, to be removed in 4.0
*/
protected $menus;

Expand All @@ -64,7 +64,7 @@ public function __construct($name, EngineInterface $templating, MenuProviderInte
$this->menuRegistry = $menuRegistry;
} else {
@trigger_error(
'Initializing '.__CLASS__.' with an array parameter is deprecated since 3.x and will be removed in 4.0.',
'Initializing '.__CLASS__.' with an array parameter is deprecated since 3.3 and will be removed in 4.0.',
E_USER_DEPRECATED
);
$this->menus = $menuRegistry;
Expand Down Expand Up @@ -105,7 +105,7 @@ public function buildEditForm(FormMapper $form, BlockInterface $block)
*/
public function validateBlock(ErrorElement $errorElement, BlockInterface $block)
{
if (($name = $block->getSetting('menu_name')) && $name !== '' && !$this->menuProvider->has($name)) {
if (($name = $block->getSetting('menu_name')) && '' !== $name && !$this->menuProvider->has($name)) {
// If we specified a menu_name, check that it exists
$errorElement->with('menu_name')
->addViolation('sonata.block.menu.not_existing', ['name' => $name])
Expand Down Expand Up @@ -155,7 +155,7 @@ protected function getFormSettingsKeys()

$choices = $this->menus;

if (count($choices) == 0) {
if (0 == count($choices)) {
$choices = $this->menuRegistry->getAliasNames();
}

Expand Down
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).

## [3.5.0](https://github.com/sonata-project/SonataBlockBundle/compare/3.4.0...3.5.0) - 2017-10-25
### Added
- support for sonata/cache 2

### Deprecated
- Option resolver BC trick.

### Fixed
- OutOfBoundsException while replacing block service default name argument

### Removed
- Support for old versions of PHP and Symfony.

## [3.4.0](https://github.com/sonata-project/SonataBlockBundle/compare/3.3.2...3.4.0) - 2017-09-19
### Added
- added block annotation
Expand Down
90 changes: 68 additions & 22 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ Some rules have to be respected about the test:
* `@codeCoverageIgnore`
* `@codeCoverageIgnoreStart`
* `@codeCoverageIgnoreEnd`
* All test methods should be prefixed by `test`. Example: `public function testItReturnsNull()`.
* All test method names must be in camel case format.
* All test methods must be prefixed by `test`. Example: `public function testItReturnsNull()`.
* As opposed, the `@test` annotation is prohibited.
* All test method names must be in camel case format.
* Most of the time, the test class should have the same name as the targeted class, suffixed by `Test`.
* The `@expectedException*` annotations are prohibited. Use `PHPUnit_Framework_TestCase::setExpectedException()`.

Expand Down Expand Up @@ -232,8 +232,62 @@ interface BarInterface
}
```

In some cases, you will have the possibility to warn the user that things will change,
and recommend a new way of doing things. You can do so by triggering the dedicated kind of error, like this:
##### Deprecation

In some cases, you might have some code parts that might become superseded by others, but could still be used by the end user.
If the concerned code is not tagged as `internal`, it must be deprecated on the stable branch, then removed.

If an alternate usage solution is possible, you **MUST** provide it in the deprecation message.

The deprecated minor version **MUST NOT** be provided. Use `x` instead. It will be updated when releasing.

Any deprecation **MUST** be documented in the corresponding `UPGRADE-[0-9].x.md`.
The documentation **MUST** be filled inside the top **unreleased** section with a sub title.

The `NEXT_MAJOR` tag should not be used for deprecation.
The `@deprecated` and `E_USER_DEPRECATED` key will be searched for before releasing the next major version.

You have three ways to deprecate things.

For class definitions, methods (or first level functions) and properties, use the `@deprecated` tag:

```php
/**
* @deprecated since 42.x, to be removed in 43.0. Use Shiny\New\ClassOfTheMonth instead.
*/
final class IAmOldAndUseless
{
}

final class StillUsedClass
{
/**
* @deprecated since 42.x, to be removed in 43.0.
*/
public $butNotThisProperty;

/**
* @deprecated since 42.x, to be removed in 43.0.
*/
public function iAmBatman()
{
echo "But this is not Gotham here.";
}
}
```

If the deprecated thing is a service, you **MUST** specify it on the service definition:

```xml
<service id="sonata.block.old" class="Sonata\Block\Old">
<argument type="service" id="security.token_storage" />
<deprecated>The "%service_id%" service is deprecated since 42.x and will be removed in 43.0.</deprecated>
</service>
```

More info: http://symfony.com/blog/new-in-symfony-2-8-deprecated-service-definitions

For everything else, not managed by the `@deprecated` tag, you **MUST** trigger a deprecation message.

```php
<?php
Expand All @@ -248,26 +302,14 @@ if (/* some condition showing the user is using the legacy way */) {
}
```

Additionally, and when applicable, you must use the `@deprecated` tag on classes or methods you wish to deprecate,
along with a message directed at the end user (as opposed to other contributors).


```php
/**
* NEXT_MAJOR: remove this method
*
* @deprecated since 3.x, to be removed in 4.0. Use Foo::bar instead.
*/
public function baz()
{
}
```
Note that the `trigger_error` usage is not necessary if the `@deprecated` tag is used.

In that case, unit tests might show your deprecation notice. You must mark such tests with the `@group legacy` annotation,
and if need be, isolate them in a new test method that can simply be removed in the non-BC PR.
In the case of a deprecation, unit tests might show your deprecation notice.
You **MUST** mark such tests with the `@group legacy` annotation and if need be,
isolate them in a new test method that can simply be removed in the non-BC PR.

Be aware that pull requests with BC breaks could be rejected
or postponed to next major release if BC is not possible.
or postponed to next major release **only** if BC is not possible.

If you are not sure what should be done, don't hesitate to open an issue about your PR project.

Expand All @@ -279,9 +321,13 @@ If you want to change some dependencies, here are the rules:
- Don't change the highest supported version to a lower one.
- Lower version dropping is accepted as a Backward Compatible change according to [semver][semver_dependencies_update],
but some extra rules must be respected here:
- PHP versions that are under the [green zone][php_supported_versions] (actively maintained) **MUST NO** be dropped, even on master.
- PHP versions that are under the [orange zone][php_supported_versions] (Security Support) **MUST NOT** be dropped on the stable branch.
- PHP versions that are under the [green zone][php_supported_versions] (Active Support) **MUST NOT** be dropped on the master branch.
- If it's a Symfony package, at least the last LTS version **MUST** be supported, even on master.
- Generally, don't drop dependency version it it doesn't have a big impact on the code.
- Backward Compatible code related to the dropped version **MUST** be dropped on the same PR.
This will allow to see if this version drop **is really worth it** or not.
Please note that we can refuse a version drop at any moment if the gain does not seem sufficient.

##### Legacy branches

Expand Down
4 changes: 2 additions & 2 deletions Cache/HttpCacheHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,11 @@ public function alterResponse(Response $response)
*/
public function updateMetadata(Response $response, BlockContextInterface $blockContext = null)
{
if ($this->currentTtl === null) {
if (null === $this->currentTtl) {
$this->currentTtl = $response->getTtl();
}

if ($response->isCacheable() !== null && $response->getTtl() < $this->currentTtl) {
if (null !== $response->isCacheable() && $response->getTtl() < $this->currentTtl) {
$this->currentTtl = $response->getTtl();
}
}
Expand Down
4 changes: 2 additions & 2 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public function getConfigTreeBuilder()
->validate()
->always(function ($value) {
foreach ($value['blocks'] as $name => &$block) {
if (count($block['contexts']) == 0) {
if (0 == count($block['contexts'])) {
$block['contexts'] = $value['default_contexts'];
}
}
Expand Down Expand Up @@ -168,7 +168,7 @@ public function getConfigTreeBuilder()
->always(function ($value) {
if (count($value) > 0) {
@trigger_error(
'The menus configuration key is deprecated since 3.x and will be removed in 4.0.',
'The menus configuration key is deprecated since 3.3 and will be removed in 4.0.',
E_USER_DEPRECATED
);
}
Expand Down
2 changes: 1 addition & 1 deletion DependencyInjection/SonataBlockExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public function configureForm(ContainerBuilder $container, array $config)
$contexts = [];

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

Expand Down
2 changes: 1 addition & 1 deletion Event/TextBlockListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TextBlockListener
public function onBlock(BlockEvent $event)
{
$content = 'This block is coming from inline event from the template';
if ($event->getSetting('admin') instanceof AdminInterface && $event->getSetting('action') == 'edit') {
if ($event->getSetting('admin') instanceof AdminInterface && 'edit' == $event->getSetting('action')) {
$admin = $event->getSetting('admin');

$content = sprintf("<p class='well'>The admin subject is <strong>%s</strong></p>", $admin->toString($admin->getSubject()));
Expand Down
2 changes: 1 addition & 1 deletion Menu/MenuRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function __construct($menus = null)
$this->names = $menus;

@trigger_error(
'The menus parameter in '.__CLASS__.' is deprecated since 3.x and will be removed in 4.0.',
'The menus parameter in '.__CLASS__.' is deprecated since 3.3 and will be removed in 4.0.',
E_USER_DEPRECATED
);
}
Expand Down
2 changes: 1 addition & 1 deletion Profiler/DataCollector/BlockDataCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public function collect(Request $request, Response $response, \Exception $except
return; // something went wrong while collecting information
}

if ($id == '_events') {
if ('_events' == $id) {
foreach ($block as $uniqid => $event) {
$this->events[$uniqid] = $event;
}
Expand Down
9 changes: 9 additions & 0 deletions UPGRADE-3.x.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
UPGRADE 3.x
===========

UPGRADE FROM 3.4 to 3.5
=======================

## Deprecated options resolver BC tricks.

Since we require at least Symfony 2.8, this BC trick is not needed anymore.

The concerned class and interface should be internal, but as they was not marked like this, we will deprecate them.

UPGRADE FROM 3.2 to 3.3
=======================

Expand Down

0 comments on commit 4ddee87

Please sign in to comment.