From 9c53ea102d5f1c50985f3f78cbaf4126de4ce7ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milan=20Felix=20=C5=A0ulc?= Date: Mon, 31 Jul 2017 12:07:15 +0200 Subject: [PATCH] Refactoring: rename namespace to Contributte, simplify CI & composer --- .editorconfig | 26 +++++++ .travis.yml | 51 ++++++++---- LICENCE | 21 +++++ composer.json | 31 ++++++-- src/DI/ParsedownExtraExtension.php | 66 +++++++++------- src/ParsedownExtraAdapter.php | 78 ++++++++++--------- .../ParsedownExtraAdapterTest.phpt | 21 ----- tests/bootstrap.php | 21 ++--- tests/cases/ParsedownExtraAdapterTest.phpt | 22 ++++++ tests/php-win.ini | 5 -- tests/tester | 3 - tests/tester.bat | 3 - 12 files changed, 217 insertions(+), 131 deletions(-) create mode 100644 .editorconfig create mode 100644 LICENCE delete mode 100644 tests/ParsedownExtra/ParsedownExtraAdapterTest.phpt create mode 100644 tests/cases/ParsedownExtraAdapterTest.phpt delete mode 100644 tests/php-win.ini delete mode 100644 tests/tester delete mode 100644 tests/tester.bat diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..0142188 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,26 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# Top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +end_of_line = lf +insert_final_newline = true + +# JS / PHP +[*.{js,php,phpt}] +charset = utf-8 +indent_style = tab +indent_size = 4 + +# NEON +[*.neon] +charset = utf-8 +indent_style = tab +indent_size = 4 + +# Composer, NPM, Travis, BitbucketPipelines +[{composer.json,package.json,.travis.yml,bitbucket-pipelines.yml}] +indent_style = space +indent_size = 2 diff --git a/.travis.yml b/.travis.yml index 196db21..5884af9 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,13 +1,16 @@ language: php + php: - - 5.6 - - 7.0 - - hhvm - - hhvm-nightly + - 5.6 + - 7.0 + - 7.1 + - hhvm matrix: + fast_finish: true + allow_failures: - - php: hhvm-nightly + - php: hhvm include: - php: 5.6 @@ -18,18 +21,38 @@ matrix: env: COMPOSER_FLAG=--prefer-lowest - php: 7.0 env: COMPOSER_FLAG=--prefer-stable + - php: 7.1 + env: COMPOSER_FLAG=--prefer-lowest + - php: 7.1 + env: COMPOSER_FLAG=--prefer-stable before_script: - # Update Composer - - composer self-update - - # Install Nette Tester - - composer update --no-interaction --prefer-source $COMPOSER_FLAG + # Composer + - travis_retry composer install --no-interaction + # Coverage + - if [[ "$TRAVIS_PHP_VERSION" == "7.1" && "$COMPOSER_FLAG" == "" ]]; then COVERAGE=1; fi script: - - vendor/bin/tester -i -p php - - vendor/bin/tester tests/ParsedownExtra -s -p php + # Quality Assurance + - travis_retry composer qa + + # Nette\Tester + - composer run-script tester + + # Nette\Tester + CodeCoverage + - if [ "$COVERAGE" != "" ]; then composer tester-coverage; fi + +after_script: + # Coverage (Coveralls) + - if [ "$COVERAGE" != "" ]; then wget https://github.com/satooshi/php-coveralls/releases/download/v1.0.1/coveralls.phar; fi + - if [ "$COVERAGE" != "" ]; then php coveralls.phar --verbose --config tests/.coveralls.yml; fi after_failure: - # Print *.actual content - - 'for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done' + # Print *.actual content + - for i in $(find tests -name \*.actual); do echo "--- $i"; cat $i; echo; echo; done + +sudo: false + +cache: + directories: + - $HOME/.composer/cache diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..aa35d2c --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2016 Contributte + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/composer.json b/composer.json index cbe90ce..717cfb3 100644 --- a/composer.json +++ b/composer.json @@ -1,26 +1,41 @@ { - "name": "minetro/latte-parsedown-extra", + "name": "contributte/latte-parsedown-extra", "description": "ParsedownExtra parser for Latte", "type": "library", "license": ["BSD-3-Clause"], - "homepage": "https://github.com/minetro/latte-parsedown-extra", + "homepage": "https://github.com/contributte/latte-parsedown-extra", "authors": [ { "name": "Milan Felix Sulc", - "homepage": "http://jfx.cz" + "homepage": "https://f3l1x.io" } ], "require": { "php": ">=5.6.0", - "nette/di": "~2.4.0", - "nette/utils": "~2.4.0", + "nette/di": "^2.4.9", + "nette/utils": "^2.4.7", "erusev/parsedown-extra": "^0.7.1", - "erusev/parsedown": "^1.6.0" + "erusev/parsedown": "^1.6.3" }, "require-dev": { - "nette/tester": "~1.7.0" + "ninjify/qa": "^0.4.0", + "ninjify/nunjuck": "^0.1.4" }, "autoload": { - "classmap": ["src/"] + "psr-4": { + "Contributte\\Parsedown\\": "src/" + } + }, + "scripts": { + "qa": [ + "linter src tests", + "codesniffer src tests" + ], + "tester": [ + "tester -s -p php --colors 1 -c tests/php-unix.ini tests/cases" + ], + "tester-coverage": [ + "tester -s -p php --colors 1 -c tests/php-unix.ini -d extension=xdebug.so --coverage ./coverage.xml --coverage-src ./src tests/cases" + ] } } diff --git a/src/DI/ParsedownExtraExtension.php b/src/DI/ParsedownExtraExtension.php index 2cbcfd8..acbfd27 100644 --- a/src/DI/ParsedownExtraExtension.php +++ b/src/DI/ParsedownExtraExtension.php @@ -1,7 +1,8 @@ 'parsedown', - ]; - - public function loadConfiguration() - { - $config = $this->validateConfig($this->defaults); - $builder = $this->getContainerBuilder(); - - $builder->addDefinition($this->prefix('parsedown')) - ->setClass('Minetro\Parsedown\ParsedownExtraAdapter'); - } - - public function beforeCompile() - { - $config = $this->validateConfig($this->defaults); - $builder = $this->getContainerBuilder(); - - if (!($templateFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory'))) { - throw new InvalidStateException('Service implemented ILatteFactory not found.'); - } - - $builder->getDefinition($templateFactory) - ->addSetup('addFilter', [$config['helper'], ['@' . $this->prefix('parsedown'), 'process']]); - } + /** @var array */ + private $defaults = [ + 'helper' => 'parsedown', + ]; + + /** + * Register services + * + * @return void + */ + public function loadConfiguration() + { + $config = $this->validateConfig($this->defaults); + $builder = $this->getContainerBuilder(); + + $builder->addDefinition($this->prefix('parsedown')) + ->setClass(ParsedownExtraAdapter::class); + } + + /** + * Decorate services + * + * @return void + */ + public function beforeCompile() + { + $config = $this->validateConfig($this->defaults); + $builder = $this->getContainerBuilder(); + + $templateFactory = $builder->getByType('Nette\Bridges\ApplicationLatte\ILatteFactory'); + if (!$templateFactory) { + throw new InvalidStateException('Service implemented ILatteFactory not found.'); + } + + $builder->getDefinition($templateFactory) + ->addSetup('addFilter', [$config['helper'], ['@' . $this->prefix('parsedown'), 'process']]); + } } diff --git a/src/ParsedownExtraAdapter.php b/src/ParsedownExtraAdapter.php index cf63a3b..f00195b 100644 --- a/src/ParsedownExtraAdapter.php +++ b/src/ParsedownExtraAdapter.php @@ -1,47 +1,55 @@ - * @method onProcess(string $text, ParsedownExtraAdapter $adapter); + * @method void onProcess(string $text, ParsedownExtraAdapter $adapter) */ -class ParsedownExtraAdapter extends Object +class ParsedownExtraAdapter { - /** @var ParsedownExtra */ - private $parsedown; - - /** @var array */ - public $onProcess = []; - - public function __construct() - { - $this->parsedown = new ParsedownExtra(); - } - - /** - * @param mixed $text - * @param string - */ - public function process($text) - { - $this->onProcess($text, $this); - return $this->parsedown->parse($text); - } - - /** - * @param mixed $line - * @param string - */ - public function processLine($line) - { - $this->onProcess($line, $this); - return $this->parsedown->line($line); - } -} \ No newline at end of file + use SmartObject; + + /** @var ParsedownExtra */ + private $parsedown; + + /** @var array */ + public $onProcess = []; + + /** + * Creates adapter + */ + public function __construct() + { + $this->parsedown = new ParsedownExtra(); + } + + /** + * @param mixed $text + * @return mixed + */ + public function process($text) + { + $this->onProcess($text, $this); + + return $this->parsedown->parse($text); + } + + /** + * @param mixed $line + * @return string + */ + public function processLine($line) + { + $this->onProcess($line, $this); + + return $this->parsedown->line($line); + } + +} diff --git a/tests/ParsedownExtra/ParsedownExtraAdapterTest.phpt b/tests/ParsedownExtra/ParsedownExtraAdapterTest.phpt deleted file mode 100644 index a9bb183..0000000 --- a/tests/ParsedownExtra/ParsedownExtraAdapterTest.phpt +++ /dev/null @@ -1,21 +0,0 @@ -Headline\n

Headline2

", $adapter->process($text)); -}); \ No newline at end of file diff --git a/tests/bootstrap.php b/tests/bootstrap.php index dd71535..d3693ed 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -3,22 +3,13 @@ /** * Test bootstrap. */ + +use Ninjify\Nunjuck\Environment; + if (@!include __DIR__ . '/../vendor/autoload.php') { - echo 'Install Nette Tester using `composer update --dev`'; - exit(1); + echo 'Install Nette Tester using `composer update --dev`'; + exit(1); } // Configure environment -Tester\Environment::setup(); -date_default_timezone_set('Europe/Prague'); - -// Create temporary directory -define('TEMP_DIR', __DIR__ . '/tmp/' . getmypid()); -@mkdir(dirname(TEMP_DIR)); // @ - directory may already exist -Tester\Helpers::purge(TEMP_DIR); - -// Test functions -function test(\Closure $function) -{ - $function(); -} +Environment::setup(__DIR__); diff --git a/tests/cases/ParsedownExtraAdapterTest.phpt b/tests/cases/ParsedownExtraAdapterTest.phpt new file mode 100644 index 0000000..3011f24 --- /dev/null +++ b/tests/cases/ParsedownExtraAdapterTest.phpt @@ -0,0 +1,22 @@ +Headline\n

Headline2

", $adapter->process($text)); +}); diff --git a/tests/php-win.ini b/tests/php-win.ini deleted file mode 100644 index 1e8525e..0000000 --- a/tests/php-win.ini +++ /dev/null @@ -1,5 +0,0 @@ -[PHP] -extension_dir=./ext - -[XDebug] -zend_extension = "php_xdebug.dll" \ No newline at end of file diff --git a/tests/tester b/tests/tester deleted file mode 100644 index fcd0fe5..0000000 --- a/tests/tester +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env sh -sh ../vendor/bin/tester ParsedownExtra -s -j 40 -log tester.log $@ -rm "./tmp" -f -R \ No newline at end of file diff --git a/tests/tester.bat b/tests/tester.bat deleted file mode 100644 index 56977d7..0000000 --- a/tests/tester.bat +++ /dev/null @@ -1,3 +0,0 @@ -@echo off -%CD%\..\vendor\bin\tester.bat %CD%\ParsedownExtra -s -j 40 -log %CD%\tester.log %* -rmdir %CD%\tmp /Q /S