diff --git a/.gitignore b/.gitignore index 22c6eb8..95620bf 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ bin/phpspec bin app/console app/logs/ +!config/example.yml +config/* diff --git a/.php_cs.php b/.php_cs.php index a29545d..0c9c397 100644 --- a/.php_cs.php +++ b/.php_cs.php @@ -6,6 +6,7 @@ ->in(__DIR__); return PhpCsFixer\Config::create() + ->setUsingCache(false) ->setRules([ '@PSR2' => true, 'linebreak_after_opening_tag' => true, diff --git a/.travis.yml b/.travis.yml index 4bb0215..1706c0e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,6 @@ before_install: install: - composer install --prefer-dist --no-interaction - - curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer script: - bin/phpspec run diff --git a/README.md b/README.md index 9523521..073075a 100644 --- a/README.md +++ b/README.md @@ -72,6 +72,26 @@ An example of crontab to push new keys every friday and create pull requests eve 0 5 * * 1 cd /path/to/nelson/ && app/console nelson:push-translation-keys > /tmp/nelson_push.log 2>&1 ``` +## Testing + +You can use the shipped docker container to develop and test. + +Launch specs in the docker container: +``` +docker-compose run --rm php bin/console phpspec run +``` + +Launch a command with XDebug: +``` +PHP_XDEBUG_ENABLED=1 docker-compose run --rm php app/console nelson:refresh-packages --config_file=community-1.x-2.x.yml +``` + +Automatically fix your code style: +``` +docker-compose run --rm php bin/php-cs-fixer fix --config=.php_cs.php +``` + ## Copyrights -Thanks to [Bouletmaton](http://www.zanorg.net/bouletmaton/) for the avatar ([bouletcorp.com](http://www.bouletcorp.com/), [zanorg.com](http://www.zanorg.com/)) +Thanks to [Bouletmaton](http://www.zanorg.net/bouletmaton/) for the avatar ([bouletcorp.com](http://www.bouletcorp.com/), +[zanorg.com](http://www.zanorg.com/)) diff --git a/app/Application.php b/app/Application.php index 945f84d..f916f32 100644 --- a/app/Application.php +++ b/app/Application.php @@ -36,9 +36,10 @@ public function __construct($name = 'crowdin', $version = 'UNKNOWN') $this->registerCommands(); $input = new ArgvInput(); - $configFile = $input->getParameterOption(['--config_file', '-c'], getenv('CROWDIN_CONFIG') ?: 'config.yml'); + $configFilename = $input->getParameterOption(['--config_file', '-c'], getenv('CROWDIN_CONFIG') ?: 'config.yml'); + $configFilePath = sprintf(__DIR__ . '/../config/%s', $configFilename); - if (!file_exists(sprintf('%s%s%s', __DIR__, DIRECTORY_SEPARATOR, $configFile))) { + if (!file_exists(sprintf($configFilePath))) { $output = new ConsoleOutput(); $output->writeln(sprintf( "\n The file %s%s%s was not found!". @@ -46,11 +47,11 @@ public function __construct($name = 'crowdin', $version = 'UNKNOWN') "\n You can use --config_file[=CONFIG_FILE] to change default configuration file.\n", __DIR__, DIRECTORY_SEPARATOR, - $configFile + $configFilePath )); } else { $loader = new YamlFileLoader($this->container, new FileLocator(__DIR__)); - $loader->load($configFile); + $loader->load($configFilePath); $this->container->compile(); } } diff --git a/composer.lock b/composer.lock index d77f2e1..b4c1cc2 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "74d99053644ae32984a5a3a88ee0a4dc", + "content-hash": "721b37f2d10289f4b66cfc025dea47e0", "packages": [ { "name": "akeneo/crowdin-api", diff --git a/app/config.example.yml b/config/example.yml similarity index 100% rename from app/config.example.yml rename to config/example.yml diff --git a/docker-compose.yml b/docker-compose.yml index 957b2ba..f24c62c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -7,3 +7,7 @@ services: volumes: - './:/srv/nelson' working_dir: '/srv/nelson' + environment: + PHP_IDE_CONFIG: 'serverName=nelson-cli' + PHP_XDEBUG_ENABLED: "${PHP_XDEBUG_ENABLED:-0}" + XDEBUG_CONFIG: 'remote_host=172.17.0.1' diff --git a/src/Akeneo/System/Executor.php b/src/Akeneo/System/Executor.php index d9b8e33..446b8bd 100644 --- a/src/Akeneo/System/Executor.php +++ b/src/Akeneo/System/Executor.php @@ -5,8 +5,6 @@ use Psr\Log\LoggerInterface; /** - * Class Executor - * * @author Nicolas Dupont * @copyright 2016 Akeneo SAS (http://www.akeneo.com) * @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) @@ -19,24 +17,18 @@ class Executor /** @var string */ protected $logFile; - /** - * @param LoggerInterface $logger - * @param string $logFile - */ - public function __construct(LoggerInterface $logger, $logFile) + public function __construct(LoggerInterface $logger, string $logFile) { $this->logger = $logger; $this->logFile = $this->getAbsolutePath($logFile); } /** - * @param string $command - * * @throws \Exception * * @return array */ - public function execute($command, $returnResult = false) + public function execute(string $command, bool $returnResult = false) { $returnVar = null; $output = []; @@ -74,12 +66,8 @@ public function execute($command, $returnResult = false) /** * Allow user to put relative path, set it absolute from main directory. - * - * @param string $logFile - * - * @return string */ - protected function getAbsolutePath($logFile) + protected function getAbsolutePath(string $logFile): string { if (!preg_match('/^\//', $logFile)) { $logFile = sprintf('%s%s..%s..%s..%s%s', diff --git a/src/Akeneo/System/Translator.php b/src/Akeneo/System/Translator.php index d07247e..b45b474 100644 --- a/src/Akeneo/System/Translator.php +++ b/src/Akeneo/System/Translator.php @@ -19,8 +19,12 @@ class Translator extends BaseTranslator /** * {@inheritdoc} */ - public function __construct($locale, MessageSelector $selector = null, $cacheDir = null, $debug = false) - { + public function __construct( + string $locale, + ?MessageSelector $selector = null, + ?string $cacheDir = null, + ?bool $debug = false + ) { parent::__construct($locale, $selector, $cacheDir, $debug); $this->addLoader('yaml', new YamlFileLoader());