Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yaml fixer #18

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"require": {
"php": ">=5.4",
"fabpot/php-cs-fixer": "^1.10"
"fabpot/php-cs-fixer": "^1.10",
"symfony/yaml": "^2"
},
"require-dev": {
"phpunit/phpunit": "^4.8"
Expand Down
99 changes: 51 additions & 48 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions src/Symfony/Upgrade/Fixer/YamlFixer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace Symfony\Upgrade\Fixer;

use Symfony\Component\Yaml\Exception\ParseException;
use Symfony\Component\Yaml\Yaml;

class YamlFixer extends AbstractFixer
{
public function fix(\SplFileInfo $file, $content)
{
if ('yml' !== strtolower($file->getExtension())) {
return $content;
}

try {
$array = Yaml::parse($content);
} catch (ParseException $ex) {

// Skipping invalid YAML files
return $content;
}

return Yaml::dump($array, 4);
}

public function getDescription()
{
return "YAML parser becomes less permissive, you should now escape mapping values containing a colon (:) or beginning by @, `, | and > signs.";
}
}
142 changes: 142 additions & 0 deletions tests/Symfony/Upgrade/Fixtures/Fixer/yaml/case1-input.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
# services.yml - twigfiddle.com

parameters:
app.oauth_user_provider.class: Fuz\AppBundle\Model\OAuthUserProvider
hwi_oauth.account.connector: Fuz\AppBundle\Connect\AccountConnect
app.form.fiddle.class: Fuz\AppBundle\Form\FiddleType
app.twig.debug_extension.class: Fuz\AppBundle\Twig\Extension\DebugExtension
app.twig.safety_extension.class: Fuz\AppBundle\Twig\Extension\SafetyExtension
app.twig.github_extension.class: Fuz\AppBundle\Twig\Extension\GitHubExtension
app.twig.hash_extension.class: Fuz\AppBundle\Twig\Extension\HashExtension
app.twig.pcre_extension.class: Fuz\AppBundle\Twig\Extension\PcreExtension
app.twig.prettify_extension.class: Fuz\AppBundle\Twig\Extension\PrettifyExtension
app.helper.doctrine_helper.class: Fuz\AppBundle\Helper\DoctrineHelper
app.subscriber.fiddle.class: Fuz\AppBundle\EventListener\FiddleSubscriber
app.subscriber.user.class: Fuz\AppBundle\EventListener\UserSubscriber
app.subscriber.user_bookmark.class: Fuz\AppBundle\EventListener\UserBookmarkSubscriber
app.utilities.class: Fuz\AppBundle\Util\Utilities
app.paginator.class: Fuz\AppBundle\Util\Paginator
app.captcha.class: Fuz\AppBundle\Util\Captcha
app.process_configuration.class: Fuz\AppBundle\Util\ProcessConfiguration
app.run_fiddle.class: Fuz\AppBundle\Service\RunFiddle
app.save_fiddle.class: Fuz\AppBundle\Service\SaveFiddle
app.search_fiddle.class: Fuz\AppBundle\Service\SearchFiddle
app.twig_extensions.class: Fuz\AppBundle\Service\TwigExtensions

services:

app.oauth_user_provider:
class: %app.oauth_user_provider.class%
arguments: [@session, @doctrine.orm.entity_manager]

hwi_oauth.account.connector:
class: %hwi_oauth.account.connector%

app.form.fiddle:
class: %app.form.fiddle.class%
arguments: [@app.process_configuration, @app.twig_extensions]
tags:
- { name: form.type }

app.twig.debug_extension:
class: %app.twig.debug_extension.class%
arguments: []
tags:
- { name: twig.extension }

app.twig.safety_extension:
class: %app.twig.safety_extension.class%
arguments: [%kernel.root_dir%]
tags:
- { name: twig.extension }

app.twig.github_extension:
class: %app.twig.github_extension.class%
arguments: [%github_repository_root%]
tags:
- { name: twig.extension }

app.twig.hash_extension:
class: %app.twig.hash_extension.class%
arguments: []
tags:
- { name: twig.extension }

app.twig.pcre_extension:
class: %app.twig.pcre_extension.class%
arguments: []
tags:
- { name: twig.extension }

app.twig.prettify_extension:
class: %app.twig.prettify_extension.class%
arguments: []
tags:
- { name: twig.extension }

app.helper.doctrine_helper:
class: %app.helper.doctrine_helper.class%
arguments: [@doctrine.orm.entity_manager]

app.subscriber.fiddle:
class: %app.subscriber.fiddle.class%
tags:
- { name: doctrine.event_subscriber, connection: default }

app.subscriber.user:
class: %app.subscriber.user.class%
tags:
- { name: doctrine.event_subscriber, connection: default }

app.subscriber.user_bookmark:
class: %app.subscriber.user_bookmark.class%
tags:
- { name: doctrine.event_subscriber, connection: default }

app.utilities:
class: %app.utilities.class%
arguments: [@logger]
tags:
- { name: monolog.logger, channel: service.utilities }

app.paginator:
class: %app.paginator.class%
arguments: [@logger, @session, @security.token_storage]
tags:
- { name: monolog.logger, channel: service.paginator }

app.captcha:
class: %app.captcha.class%
arguments: [@logger, @session, @doctrine.orm.entity_manager, %web%]
tags:
- { name: monolog.logger, channel: service.captcha }

app.process_configuration:
class: %app.process_configuration.class%
arguments: [@logger, %process%, %kernel.environment%]
tags:
- { name: monolog.logger, channel: service.process_configuration }

app.run_fiddle:
class: %app.run_fiddle.class%
arguments: [@logger, @filesystem, @app.utilities, @app.process_configuration, %process%]
tags:
- { name: monolog.logger, channel: service.run_fiddle }

app.save_fiddle:
class: %app.save_fiddle.class%
arguments: [@logger, @app.utilities, @app.helper.doctrine_helper, @doctrine.orm.entity_manager, @session, @router, %web%]
tags:
- { name: monolog.logger, channel: service.save_fiddle }

app.search_fiddle:
class: %app.search_fiddle.class%
arguments: [@logger, @doctrine.orm.entity_manager, @app.paginator, %web%]
tags:
- { name: monolog.logger, channel: service.search_fiddle }

app.twig_extensions:
class: %app.twig_extensions.class%
arguments: [@logger, @app.process_configuration, %kernel.environment%]
tags:
- { name: monolog.logger, channel: service.twig_extensions }
Loading