Skip to content

Commit

Permalink
Merge pull request #29 from koriym/spike
Browse files Browse the repository at this point in the history
TwigErrorPage when exception thrown
  • Loading branch information
koriym authored May 30, 2018
2 parents 8362a77 + 7ac180a commit 44254ca
Show file tree
Hide file tree
Showing 27 changed files with 602 additions and 176 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ vendor/
build/
composer.lock
.DS_Store
.php_cs.cache
245 changes: 122 additions & 123 deletions .php_cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,126 +7,125 @@ This file is part of the Madapaja.TwigModule package.
EOF;

return \PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules(array(
'@PSR2' => true,
'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'separate' => 'none'],
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false],
'blank_line_after_opening_tag' => true,
'blank_line_after_namespace' => false,
'blank_line_before_return' => true,
'cast_spaces' => true,
// 'class_keyword_remove' => true,
'combine_consecutive_unsets' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => true,
'declare_strict_types' => false,
'dir_constant' => true,
'ereg_to_preg' => true,
'function_typehint_space' => true,
'general_phpdoc_annotation_remove' => true,
'hash_to_slash_comment' => true,
'heredoc_to_nowdoc' => true,
'include' => true,
'indentation_type' => true,
'is_null' => ['use_yoda_style' => false],
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
// 'mb_str_functions' => true,
'method_separation' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
// 'native_function_invocation' => true,
'new_with_braces' => false, //
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_blank_lines_before_namespace' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'useTrait'],
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => ['use' => 'echo'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_php4_constructor' => false,
'no_short_bool_cast' => true,
'no_short_echo_tag' => false,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_fqcn_annotation' => true,
'php_unit_strict' => true,
// 'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'],
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
// 'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
// 'phpdoc_summary' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
// 'pre_increment' => true,
'protected_to_private' => true,
'psr0' => true,
'psr4' => true,
'random_api_migration' => true,
'return_type_declaration' => ['space_before' => 'one'],
'self_accessor' => true,
'short_scalar_cast' => true,
// 'silenced_deprecation_error' => true,
// 'simplified_null_return' => true,
// 'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
// 'strict_comparison' => true,
'ternary_operator_spaces' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
// 'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true
))
->setFinder(
PhpCsFixer\Finder::create()
->exclude('tests/Fake')
->exclude('src-data')
->exclude('src-deprecated')
->in(__DIR__)
)->setLineEnding("\n")
->setUsingCache(false);
->setRiskyAllowed(true)
->setRules(array(
'@PSR2' => true,
'header_comment' => ['header' => $header, 'commentType' => 'PHPDoc', 'separate' => 'none'],
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => ['align_equals' => false, 'align_double_arrow' => false],
'blank_line_after_opening_tag' => true,
'blank_line_after_namespace' => false,
'blank_line_before_return' => true,
'cast_spaces' => true,
// 'class_keyword_remove' => true,
'combine_consecutive_unsets' => true,
'concat_space' => ['spacing' => 'one'],
'declare_equal_normalize' => true,
'declare_strict_types' => false,
'dir_constant' => true,
'ereg_to_preg' => true,
'function_typehint_space' => true,
'general_phpdoc_annotation_remove' => true,
'hash_to_slash_comment' => true,
'heredoc_to_nowdoc' => true,
'include' => true,
'indentation_type' => true,
'is_null' => ['use_yoda_style' => false],
'linebreak_after_opening_tag' => true,
'lowercase_cast' => true,
// 'mb_str_functions' => true,
'method_separation' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'native_function_invocation' => true,
'new_with_braces' => false, //
'no_alias_functions' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_blank_lines_before_namespace' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
'no_extra_consecutive_blank_lines' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'useTrait'],
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => ['use' => 'echo'],
'no_multiline_whitespace_around_double_arrow' => true,
'no_multiline_whitespace_before_semicolons' => true,
'no_php4_constructor' => false,
'no_short_bool_cast' => true,
'no_short_echo_tag' => false,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_around_offset' => true,
'no_trailing_comma_in_list_call' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unreachable_default_argument_value' => true,
'no_unused_imports' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_before_comma_in_array' => true,
'no_whitespace_in_blank_line' => true,
'normalize_index_brace' => true,
'not_operator_with_space' => false,
'not_operator_with_successor_space' => true,
'object_operator_without_whitespace' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'php_unit_construct' => true,
'php_unit_dedicate_assert' => true,
'php_unit_fqcn_annotation' => true,
'php_unit_strict' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => true,
'phpdoc_annotation_without_dot' => true,
'phpdoc_indent' => true,
'phpdoc_inline_tag' => true,
'phpdoc_no_access' => true,
'phpdoc_no_alias_tag' => ['property-read' => 'property', 'property-write' => 'property', 'type' => 'var'],
'phpdoc_no_empty_return' => true,
'phpdoc_no_package' => true,
'phpdoc_no_useless_inheritdoc' => true,
'phpdoc_order' => true,
'phpdoc_return_self_reference' => true,
'phpdoc_scalar' => true,
'phpdoc_separation' => true,
'phpdoc_single_line_var_spacing' => true,
// 'phpdoc_summary' => true,
'phpdoc_to_comment' => true,
'phpdoc_trim' => true,
'phpdoc_types' => true,
'phpdoc_var_without_name' => true,
'pow_to_exponentiation' => true,
// 'pre_increment' => true,
'protected_to_private' => true,
'psr0' => true,
'psr4' => true,
'random_api_migration' => true,
'return_type_declaration' => ['space_before' => 'one'],
'self_accessor' => true,
'short_scalar_cast' => true,
// 'silenced_deprecation_error' => true,
'simplified_null_return' => true,
// 'single_blank_line_before_namespace' => true,
'single_quote' => true,
'space_after_semicolon' => true,
'standardize_not_equals' => true,
// 'strict_comparison' => true,
'ternary_operator_spaces' => true,
'strict_param' => true,
'ternary_to_null_coalescing' => true,
// 'trailing_comma_in_multiline_array' => true,
'trim_array_spaces' => true,
'unary_operator_spaces' => true,
'whitespace_after_comma_in_array' => true
))
->setFinder(
PhpCsFixer\Finder::create()
->exclude('tests/Fake')
->exclude('tests/tmp')
->exclude('src-data')
->in(__DIR__)
)->setLineEnding("\n");
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ before_script:
- composer self-update
- composer update $DEPENDENCIES
script:
- vendor/bin/phpmd src text phpmd.xml
- ./vendor/bin/phpunit --coverage-clover=coverage.clover;
- if [ "$TRAVIS_PHP_VERSION" = "7.1" ]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar -O php-cs-fixer && php php-cs-fixer fix --config=.php_cs -v --dry-run --using-cache=no --path-mode=intersection `git diff --name-only --diff-filter=ACMRTUXB $TRAVIS_COMMIT_RANGE`; fi

Expand Down
18 changes: 9 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@
}
],
"require": {
"ray/di": "^2.5.3",
"bear/sunday": "^1.1",
"php": ">=7.0.0",
"bear/sunday": "^1.2",
"bear/app-meta": "^1.1",
"twig/twig": "^2.0",
"mobiledetect/mobiledetectlib": "^2.7"
"twig/twig": "^2.4.8",
"mobiledetect/mobiledetectlib": "^2.7",
"ray/di": "^2.7"
},
"require-dev": {
"phpunit/phpunit": "~5.7 < 6.0",
Expand All @@ -36,11 +37,10 @@
}
},
"scripts": {
"test": ["@cs", "php -n ./vendor/bin/phpunit"],
"cs": ["php -n ./vendor/bin/phpcs --standard=./phpcs.xml src"],
"cs-fix": ["php -n ./vendor/bin/phpcbf src"],
"test": ["@setup", "vendor/bin/phpunit"],
"tests": ["@cs", "phpstan analyse -l max src tests -c phpstan.neon --no-progress", "@test"],
"coverage": ["php -dzend_extension=xdebug.so ./vendor/bin/phpunit --coverage-text --coverage-html=build/coverage"],
"md": ["phpmd src text phpmd.xml"],
"check-all": ["@cs", "@md", "@coverage"]
"cs": ["php-cs-fixer fix -v --dry-run", "phpcs --standard=phpcs.xml src;"],
"cs-fix": ["php-cs-fixer fix -v", "phpcbf src tests"]
}
}
19 changes: 19 additions & 0 deletions src/Annotation/TwigErrorPath.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php
/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule\Annotation;

use Ray\Di\Di\Qualifier;

/**
* @Annotation
* @Target("METHOD")
* @Qualifier
*/
final class TwigErrorPath
{
public $value;
}
44 changes: 44 additions & 0 deletions src/ErrorPagerRenderer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php
/**
* This file is part of the Madapaja.TwigModule package.
*
* @license http://opensource.org/licenses/MIT MIT
*/
namespace Madapaja\TwigModule;

use BEAR\Resource\RenderInterface;
use BEAR\Resource\ResourceObject;
use Madapaja\TwigModule\Annotation\TwigErrorPath;

class ErrorPagerRenderer implements RenderInterface
{
/**
* @var \Twig_Environment
*/
private $twig;

private $errorPage;

/**
* @TwigErrorPath("errorPage")
*/
public function __construct(\Twig_Environment $twig, string $errorPage)
{
$this->twig = $twig;
$this->errorPage = $errorPage;
}

/**
* @throws \Twig_Error_Loader
* @throws \Twig_Error_Runtime
* @throws \Twig_Error_Syntax
*
* @return string
*/
public function render(ResourceObject $ro)
{
$ro->view = $this->twig->render($this->errorPage, $ro->body);

return $ro->view;
}
}
8 changes: 5 additions & 3 deletions src/MobileTemplateFinder.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class MobileTemplateFinder implements TemplateFinderInterface

/**
* @TwigPaths("paths")
*
* @param mixed $userAgent
*/
public function __construct($userAgent = '', array $paths = [])
{
Expand All @@ -44,10 +46,10 @@ public function __invoke(string $name) : string
$detect = new \Mobile_Detect(null, $this->userAgent);
$isMobile = $detect->isMobile() && ! $detect->isTablet();
if ($isMobile) {
$mobilePath = str_replace('.html.twig', '.mobile.twig', $templatePath);
$mobilePath = \str_replace('.html.twig', '.mobile.twig', $templatePath);
foreach ($this->paths as $path) {
$mobileFile = sprintf('%s/%s', $path, $mobilePath);
if (file_exists($mobileFile)) {
$mobileFile = \sprintf('%s/%s', $path, $mobilePath);
if (\file_exists($mobileFile)) {
return $mobilePath;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/OptionProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class OptionProvider implements ProviderInterface
* @Named("isDebug=Madapaja\TwigModule\Annotation\TwigDebug")
* @SuppressWarnings(PHPMD.BooleanArgumentFlag)
*/
public function __construct(AbstractAppMeta $appMeta, $isDebug = false)
public function __construct(AbstractAppMeta $appMeta, bool $isDebug = false)
{
$this->appMeta = $appMeta;
$this->isDebug = $isDebug;
Expand Down
Loading

0 comments on commit 44254ca

Please sign in to comment.