Merge branch 'develop'
All checks were successful
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good
All checks were successful
timw4mail/HummingBirdAnimeClient/pipeline/head This commit looks good
This commit is contained in:
commit
144718866d
4
.gitignore
vendored
4
.gitignore
vendored
@ -151,3 +151,7 @@ public/mal_mappings.json
|
||||
.is-dev
|
||||
|
||||
tmp
|
||||
tools/vendor/
|
||||
tools/phinx/vendor/
|
||||
/.php-cs-fixer.php
|
||||
/.php-cs-fixer.cache
|
534
.php-cs-fixer.dist.php
Normal file
534
.php-cs-fixer.dist.php
Normal file
@ -0,0 +1,534 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Nexus\CsConfig\Factory;
|
||||
use PhpCsFixer\{Config, Finder};
|
||||
|
||||
$finder = Finder::create()
|
||||
->in([
|
||||
__DIR__ . '/src',
|
||||
__DIR__ . '/tests',
|
||||
__DIR__ . '/tools',
|
||||
])
|
||||
->exclude([
|
||||
'vendor',
|
||||
]);
|
||||
|
||||
return (new Config())
|
||||
->setRiskyAllowed(TRUE)
|
||||
->setFinder($finder)
|
||||
->setIndent(' ')
|
||||
->setRules([
|
||||
'align_multiline_comment' => false,
|
||||
'array_indentation' => true,
|
||||
'array_push' => true,
|
||||
'array_syntax' => ['syntax' => 'short'],
|
||||
'assign_null_coalescing_to_coalesce_equal' => true,
|
||||
'backtick_to_shell_exec' => true,
|
||||
'binary_operator_spaces' => [
|
||||
'default' => 'single_space',
|
||||
'operators' => [
|
||||
'=' => NULL,
|
||||
'&' => NULL,
|
||||
]
|
||||
],
|
||||
'blank_line_after_namespace' => true,
|
||||
'blank_line_after_opening_tag' => false,
|
||||
'blank_line_before_statement' => [
|
||||
'statements' => [
|
||||
// 'case',
|
||||
'continue',
|
||||
'declare',
|
||||
'default',
|
||||
'do',
|
||||
'exit',
|
||||
'for',
|
||||
'foreach',
|
||||
'goto',
|
||||
'return',
|
||||
'switch',
|
||||
'throw',
|
||||
'try',
|
||||
'while',
|
||||
'yield',
|
||||
'yield_from',
|
||||
],
|
||||
],
|
||||
// 'braces' => [
|
||||
// 'allow_single_line_anonymous_class_with_empty_body' => true,
|
||||
// 'allow_single_line_closure' => true,
|
||||
// 'position_after_anonymous_constructs' => 'same',
|
||||
// 'position_after_control_structures' => 'next',
|
||||
// 'position_after_functions_and_oop_constructs' => 'next',
|
||||
// ],
|
||||
'cast_spaces' => ['space' => 'single'],
|
||||
'class_attributes_separation' => [
|
||||
'elements' => [
|
||||
'const' => 'none',
|
||||
'property' => 'none',
|
||||
'method' => 'one',
|
||||
'trait_import' => 'none',
|
||||
],
|
||||
],
|
||||
'class_definition' => [
|
||||
'multi_line_extends_each_single_line' => true,
|
||||
'single_item_single_line' => true,
|
||||
'single_line' => true,
|
||||
'space_before_parenthesis' => true,
|
||||
],
|
||||
'class_reference_name_casing' => true,
|
||||
'clean_namespace' => true,
|
||||
'combine_consecutive_issets' => true,
|
||||
'combine_consecutive_unsets' => true,
|
||||
'combine_nested_dirname' => true,
|
||||
'comment_to_phpdoc' => [
|
||||
'ignored_tags' => [
|
||||
'todo',
|
||||
'codeCoverageIgnore',
|
||||
'codeCoverageIgnoreStart',
|
||||
'codeCoverageIgnoreEnd',
|
||||
'phpstan-ignore-line',
|
||||
'phpstan-ignore-next-line',
|
||||
],
|
||||
],
|
||||
'compact_nullable_typehint' => true,
|
||||
'concat_space' => ['spacing' => 'one'],
|
||||
'constant_case' => ['case' => 'upper'],
|
||||
'control_structure_braces' => true,
|
||||
'control_structure_continuation_position' => ['position' => 'next_line'],
|
||||
'curly_braces_position' => [
|
||||
'allow_single_line_anonymous_functions' => true,
|
||||
'allow_single_line_empty_anonymous_classes' => true,
|
||||
'anonymous_functions_opening_brace' => 'same_line',
|
||||
'classes_opening_brace' => 'next_line_unless_newline_at_signature_end',
|
||||
'control_structures_opening_brace' => 'next_line_unless_newline_at_signature_end',
|
||||
'functions_opening_brace' => 'next_line_unless_newline_at_signature_end',
|
||||
],
|
||||
'date_time_immutable' => false,
|
||||
'declare_equal_normalize' => ['space' => 'none'],
|
||||
'declare_parentheses' => true,
|
||||
'declare_strict_types' => true,
|
||||
'dir_constant' => true,
|
||||
'doctrine_annotation_array_assignment' => false,
|
||||
'doctrine_annotation_braces' => false,
|
||||
'doctrine_annotation_indentation' => false,
|
||||
'doctrine_annotation_spaces' => false,
|
||||
'echo_tag_syntax' => [
|
||||
'format' => 'short',
|
||||
'long_function' => 'echo',
|
||||
'shorten_simple_statements_only' => false,
|
||||
],
|
||||
'elseif' => false,
|
||||
'empty_loop_body' => ['style' => 'braces'],
|
||||
'empty_loop_condition' => ['style' => 'while'],
|
||||
'encoding' => true,
|
||||
'error_suppression' => [
|
||||
'mute_deprecation_error' => true,
|
||||
'noise_remaining_usages' => false,
|
||||
'noise_remaining_usages_exclude' => [],
|
||||
],
|
||||
'escape_implicit_backslashes' => [
|
||||
'double_quoted' => false,
|
||||
'heredoc_syntax' => false,
|
||||
'single_quoted' => false,
|
||||
],
|
||||
'explicit_indirect_variable' => false,
|
||||
'explicit_string_variable' => false,
|
||||
'final_class' => false,
|
||||
'final_internal_class' => [
|
||||
'annotation_exclude' => ['@no-final'],
|
||||
'annotation_include' => ['@internal'],
|
||||
'consider_absent_docblock_as_internal_class' => false,
|
||||
],
|
||||
'final_public_method_for_abstract_class' => false,
|
||||
'fopen_flag_order' => true,
|
||||
'fopen_flags' => ['b_mode' => true],
|
||||
'full_opening_tag' => true,
|
||||
'fully_qualified_strict_types' => true,
|
||||
'function_declaration' => ['closure_function_spacing' => 'one'],
|
||||
'function_to_constant' => [
|
||||
'functions' => [
|
||||
'get_called_class',
|
||||
'get_class',
|
||||
'get_class_this',
|
||||
'php_sapi_name',
|
||||
'phpversion',
|
||||
'pi',
|
||||
],
|
||||
],
|
||||
'function_typehint_space' => true,
|
||||
'general_phpdoc_annotation_remove' => false,
|
||||
'general_phpdoc_tag_rename' => false,
|
||||
'get_class_to_class_keyword' => false,
|
||||
'global_namespace_import' => [
|
||||
'import_constants' => true,
|
||||
'import_functions' => true,
|
||||
'import_classes' => true,
|
||||
],
|
||||
'group_import' => true,
|
||||
'header_comment' => false, // false by default
|
||||
// 'heredoc_indentation' => ['indentation' => 'start_plus_one'],
|
||||
'heredoc_to_nowdoc' => true,
|
||||
'implode_call' => true,
|
||||
'include' => true,
|
||||
'increment_style' => ['style' => 'post'],
|
||||
'indentation_type' => true,
|
||||
'integer_literal_case' => true,
|
||||
'is_null' => true,
|
||||
'lambda_not_used_import' => true,
|
||||
'line_ending' => true,
|
||||
'linebreak_after_opening_tag' => false,
|
||||
'list_syntax' => ['syntax' => 'short'],
|
||||
'logical_operators' => true,
|
||||
'lowercase_cast' => true,
|
||||
'lowercase_keywords' => true,
|
||||
'lowercase_static_reference' => true,
|
||||
'magic_constant_casing' => true,
|
||||
'magic_method_casing' => true,
|
||||
'mb_str_functions' => false,
|
||||
'method_argument_space' => [
|
||||
'after_heredoc' => false,
|
||||
'keep_multiple_spaces_after_comma' => false,
|
||||
'on_multiline' => 'ensure_fully_multiline',
|
||||
],
|
||||
'method_chaining_indentation' => true,
|
||||
'modernize_strpos' => false, // requires 8.0+
|
||||
'modernize_types_casting' => true,
|
||||
'multiline_comment_opening_closing' => true,
|
||||
'multiline_whitespace_before_semicolons' => ['strategy' => 'no_multi_line'],
|
||||
'native_constant_invocation' => false,
|
||||
'native_function_casing' => true,
|
||||
'native_function_invocation' => false,
|
||||
'native_function_type_declaration_casing' => true,
|
||||
'new_with_braces' => true,
|
||||
'no_alias_functions' => ['sets' => ['@all']],
|
||||
'no_alias_language_construct_call' => true,
|
||||
'no_alternative_syntax' => ['fix_non_monolithic_code' => false],
|
||||
'no_binary_string' => true,
|
||||
'no_blank_lines_after_class_opening' => true,
|
||||
'no_blank_lines_after_phpdoc' => true,
|
||||
'no_blank_lines_before_namespace' => false, // conflicts with `single_blank_line_before_namespace`
|
||||
'no_break_comment' => ['comment_text' => 'no break'],
|
||||
'no_closing_tag' => true,
|
||||
'no_empty_comment' => true,
|
||||
'no_empty_phpdoc' => true,
|
||||
'no_empty_statement' => true,
|
||||
'no_extra_blank_lines' => ['tokens' => ['extra']],
|
||||
'no_homoglyph_names' => true,
|
||||
'no_leading_import_slash' => true,
|
||||
'no_leading_namespace_whitespace' => true,
|
||||
'no_mixed_echo_print' => ['use' => 'echo'],
|
||||
'no_multiline_whitespace_around_double_arrow' => true,
|
||||
'no_null_property_initialization' => true,
|
||||
'no_short_bool_cast' => true,
|
||||
'no_singleline_whitespace_before_semicolons' => true,
|
||||
'no_space_around_double_colon' => true,
|
||||
'no_spaces_after_function_name' => true,
|
||||
'no_spaces_around_offset' => ['positions' => ['inside', 'outside']],
|
||||
'no_spaces_inside_parenthesis' => true,
|
||||
'no_superfluous_elseif' => true,
|
||||
'no_superfluous_phpdoc_tags' => [
|
||||
'allow_mixed' => true,
|
||||
'allow_unused_params' => true,
|
||||
'remove_inheritdoc' => false,
|
||||
],
|
||||
'no_trailing_comma_in_singleline' => true,
|
||||
'no_trailing_whitespace' => true,
|
||||
'no_trailing_whitespace_in_comment' => true,
|
||||
'no_trailing_whitespace_in_string' => true,
|
||||
'no_unneeded_control_parentheses' => [
|
||||
'statements' => [
|
||||
'break',
|
||||
'clone',
|
||||
'continue',
|
||||
'echo_print',
|
||||
'return',
|
||||
'switch_case',
|
||||
'yield',
|
||||
],
|
||||
],
|
||||
'no_unneeded_curly_braces' => ['namespaces' => true],
|
||||
'no_unneeded_final_method' => ['private_methods' => true],
|
||||
'no_unneeded_import_alias' => true,
|
||||
'no_unreachable_default_argument_value' => true,
|
||||
'no_unset_cast' => true,
|
||||
'no_unset_on_property' => false,
|
||||
'no_unused_imports' => true,
|
||||
'no_useless_else' => true,
|
||||
'no_useless_return' => true,
|
||||
'no_useless_sprintf' => true,
|
||||
'no_whitespace_before_comma_in_array' => ['after_heredoc' => true],
|
||||
'no_whitespace_in_blank_line' => true,
|
||||
'non_printable_character' => ['use_escape_sequences_in_strings' => true],
|
||||
'normalize_index_brace' => true,
|
||||
'not_operator_with_space' => true,
|
||||
'not_operator_with_successor_space' => true,
|
||||
'nullable_type_declaration_for_default_null_value' => ['use_nullable_type_declaration' => true],
|
||||
'object_operator_without_whitespace' => true,
|
||||
'operator_linebreak' => ['only_booleans' => true, 'position' => 'beginning'],
|
||||
'ordered_class_elements' => [
|
||||
'order' => [
|
||||
'use_trait',
|
||||
'case',
|
||||
'constant_public',
|
||||
'constant_protected',
|
||||
'constant_private',
|
||||
'property_public',
|
||||
'property_protected',
|
||||
'property_private',
|
||||
'construct',
|
||||
'destruct',
|
||||
'magic',
|
||||
],
|
||||
'sort_algorithm' => 'none',
|
||||
],
|
||||
'ordered_imports' => [
|
||||
'sort_algorithm' => 'alpha',
|
||||
'imports_order' => ['class', 'function', 'const'],
|
||||
],
|
||||
'ordered_interfaces' => false,
|
||||
'ordered_traits' => false,
|
||||
'php_unit_construct' => [
|
||||
'assertions' => [
|
||||
'assertSame',
|
||||
'assertEquals',
|
||||
'assertNotEquals',
|
||||
'assertNotSame',
|
||||
],
|
||||
],
|
||||
'php_unit_dedicate_assert' => ['target' => 'newest'],
|
||||
'php_unit_dedicate_assert_internal_type' => ['target' => 'newest'],
|
||||
'php_unit_expectation' => ['target' => 'newest'],
|
||||
'php_unit_fqcn_annotation' => true,
|
||||
'php_unit_internal_class' => ['types' => ['final']],
|
||||
'php_unit_method_casing' => ['case' => 'camel_case'],
|
||||
'php_unit_mock' => ['target' => 'newest'],
|
||||
'php_unit_mock_short_will_return' => true,
|
||||
'php_unit_namespaced' => ['target' => 'newest'],
|
||||
'php_unit_no_expectation_annotation' => [
|
||||
'target' => 'newest',
|
||||
'use_class_const' => true,
|
||||
],
|
||||
'php_unit_set_up_tear_down_visibility' => true,
|
||||
'php_unit_size_class' => false,
|
||||
// 'php_unit_strict' => [
|
||||
// 'assertions' => [
|
||||
// 'assertAttributeEquals',
|
||||
// 'assertAttributeNotEquals',
|
||||
// 'assertEquals',
|
||||
// 'assertNotEquals',
|
||||
// ],
|
||||
// ],
|
||||
'php_unit_test_annotation' => ['style' => 'prefix'],
|
||||
'php_unit_test_case_static_method_calls' => [
|
||||
'call_type' => 'this',
|
||||
'methods' => [],
|
||||
],
|
||||
'php_unit_test_class_requires_covers' => false,
|
||||
'phpdoc_add_missing_param_annotation' => ['only_untyped' => true],
|
||||
'phpdoc_align' => [
|
||||
'align' => 'left'
|
||||
],
|
||||
'phpdoc_annotation_without_dot' => false,
|
||||
'phpdoc_indent' => true,
|
||||
'phpdoc_inline_tag_normalizer' => [
|
||||
'tags' => [
|
||||
'example',
|
||||
'id',
|
||||
'internal',
|
||||
'inheritdoc',
|
||||
'inheritdocs',
|
||||
'link',
|
||||
'source',
|
||||
'toc',
|
||||
'tutorial',
|
||||
],
|
||||
],
|
||||
'phpdoc_line_span' => [
|
||||
'const' => 'multi',
|
||||
'method' => 'multi',
|
||||
'property' => 'multi',
|
||||
],
|
||||
'phpdoc_no_access' => true,
|
||||
'phpdoc_no_empty_return' => false,
|
||||
'phpdoc_no_package' => false,
|
||||
'phpdoc_no_useless_inheritdoc' => true,
|
||||
'phpdoc_order' => true,
|
||||
'phpdoc_order_by_value' => [
|
||||
'annotations' => [
|
||||
'author',
|
||||
'covers',
|
||||
'coversNothing',
|
||||
'dataProvider',
|
||||
'depends',
|
||||
'group',
|
||||
'internal',
|
||||
'method',
|
||||
'property',
|
||||
'property-read',
|
||||
'property-write',
|
||||
'requires',
|
||||
'throws',
|
||||
'uses',
|
||||
],
|
||||
],
|
||||
'phpdoc_return_self_reference' => [
|
||||
'replacements' => [
|
||||
'this' => '$this',
|
||||
'@this' => '$this',
|
||||
'$self' => 'self',
|
||||
'@self' => 'self',
|
||||
'$static' => 'static',
|
||||
'@static' => 'static',
|
||||
],
|
||||
],
|
||||
'phpdoc_scalar' => [
|
||||
'types' => [
|
||||
'boolean',
|
||||
'callback',
|
||||
'double',
|
||||
'integer',
|
||||
'real',
|
||||
'str',
|
||||
],
|
||||
],
|
||||
'phpdoc_separation' => false,
|
||||
'phpdoc_single_line_var_spacing' => true,
|
||||
'phpdoc_summary' => false,
|
||||
'phpdoc_tag_casing' => ['tags' => ['inheritDoc']],
|
||||
'phpdoc_tag_type' => ['tags' => ['inheritDoc' => 'inline']],
|
||||
'phpdoc_to_comment' => false,
|
||||
'phpdoc_to_param_type' => false,
|
||||
'phpdoc_to_property_type' => false,
|
||||
'phpdoc_to_return_type' => false,
|
||||
'phpdoc_trim' => true,
|
||||
'phpdoc_trim_consecutive_blank_line_separation' => true,
|
||||
'phpdoc_types' => ['groups' => ['simple', 'alias', 'meta']],
|
||||
'phpdoc_types_order' => [
|
||||
'null_adjustment' => 'always_last',
|
||||
'sort_algorithm' => 'alpha',
|
||||
],
|
||||
'phpdoc_var_annotation_correct_order' => true,
|
||||
'phpdoc_var_without_name' => true,
|
||||
'pow_to_exponentiation' => true,
|
||||
'protected_to_private' => true,
|
||||
'psr_autoloading' => ['dir' => null],
|
||||
'random_api_migration' => [
|
||||
'replacements' => [
|
||||
'getrandmax' => 'mt_getrandmax',
|
||||
'rand' => 'mt_rand',
|
||||
'srand' => 'mt_srand',
|
||||
],
|
||||
],
|
||||
'regular_callable_call' => true,
|
||||
'return_assignment' => true,
|
||||
'return_type_declaration' => ['space_before' => 'none'],
|
||||
'self_accessor' => false,
|
||||
'self_static_accessor' => true,
|
||||
'semicolon_after_instruction' => false,
|
||||
'set_type_to_cast' => true,
|
||||
'short_scalar_cast' => true,
|
||||
'simple_to_complex_string_variable' => true,
|
||||
'simplified_if_return' => true,
|
||||
'simplified_null_return' => false,
|
||||
'single_blank_line_at_eof' => true,
|
||||
'single_blank_line_before_namespace' => true,
|
||||
'single_class_element_per_statement' => ['elements' => ['const', 'property']],
|
||||
'single_import_per_statement' => false,
|
||||
'single_line_after_imports' => true,
|
||||
'single_line_comment_style' => ['comment_types' => ['asterisk', 'hash']],
|
||||
'single_line_throw' => false,
|
||||
'single_quote' => ['strings_containing_single_quote_chars' => false],
|
||||
'single_space_around_construct' => [
|
||||
'constructs_followed_by_a_single_space' => [
|
||||
'abstract',
|
||||
'as',
|
||||
'attribute',
|
||||
'break',
|
||||
'case',
|
||||
'catch',
|
||||
'class',
|
||||
'clone',
|
||||
'comment',
|
||||
'const',
|
||||
'const_import',
|
||||
'continue',
|
||||
'do',
|
||||
'echo',
|
||||
'else',
|
||||
'elseif',
|
||||
'extends',
|
||||
'final',
|
||||
'finally',
|
||||
'for',
|
||||
'foreach',
|
||||
'function',
|
||||
'function_import',
|
||||
'global',
|
||||
'goto',
|
||||
'if',
|
||||
'implements',
|
||||
'include',
|
||||
'include_once',
|
||||
'instanceof',
|
||||
'insteadof',
|
||||
'interface',
|
||||
'match',
|
||||
'named_argument',
|
||||
'new',
|
||||
'open_tag_with_echo',
|
||||
'php_doc',
|
||||
'php_open',
|
||||
'print',
|
||||
'private',
|
||||
'protected',
|
||||
'public',
|
||||
'require',
|
||||
'require_once',
|
||||
'return',
|
||||
'static',
|
||||
'throw',
|
||||
'trait',
|
||||
'try',
|
||||
'use',
|
||||
'use_lambda',
|
||||
'use_trait',
|
||||
'var',
|
||||
'while',
|
||||
'yield',
|
||||
'yield_from',
|
||||
],
|
||||
],
|
||||
'single_trait_insert_per_statement' => true,
|
||||
'space_after_semicolon' => ['remove_in_empty_for_expressions' => true],
|
||||
'standardize_increment' => true,
|
||||
'standardize_not_equals' => true,
|
||||
'statement_indentation' => true,
|
||||
'static_lambda' => true,
|
||||
'strict_comparison' => true,
|
||||
'strict_param' => true,
|
||||
'string_length_to_empty' => true,
|
||||
'string_line_ending' => true,
|
||||
'switch_case_semicolon_to_colon' => true,
|
||||
'switch_case_space' => true,
|
||||
'switch_continue_to_break' => true,
|
||||
'ternary_operator_spaces' => true,
|
||||
'ternary_to_elvis_operator' => true,
|
||||
'ternary_to_null_coalescing' => true,
|
||||
'trailing_comma_in_multiline' => [
|
||||
'after_heredoc' => true,
|
||||
'elements' => ['arrays'],
|
||||
],
|
||||
'trim_array_spaces' => true,
|
||||
'types_spaces' => ['space' => 'none'],
|
||||
'unary_operator_spaces' => false,
|
||||
'use_arrow_functions' => true,
|
||||
'visibility_required' => ['elements' => ['const', 'method', 'property']],
|
||||
'void_return' => false, // changes method signature
|
||||
'whitespace_after_comma_in_array' => true,
|
||||
'yoda_style' => [
|
||||
'equal' => false,
|
||||
'identical' => null,
|
||||
'less_and_greater' => false,
|
||||
'always_move_variable' => false,
|
||||
],
|
||||
]);
|
@ -4,6 +4,8 @@ install:
|
||||
- composer install --ignore-platform-reqs
|
||||
|
||||
php:
|
||||
- 8.0
|
||||
- 8.1
|
||||
- nightly
|
||||
|
||||
script:
|
||||
|
@ -1,7 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## Version 5.3
|
||||
* Update PHP requirement to 8.2
|
||||
|
||||
## Version 5.2
|
||||
* Updated PHP requirement to 8
|
||||
* Updated PHP requirement to 8.1
|
||||
* Updated to support PHP 8.2
|
||||
* Improve Anilist <-> Kitsu mappings to be more reliable
|
||||
|
||||
## Version 5.1
|
||||
* Added session check, so when coming back to a page, if the session is expired, the page will refresh.
|
||||
|
27
Jenkinsfile
vendored
27
Jenkinsfile
vendored
@ -10,10 +10,23 @@ pipeline {
|
||||
sh 'php composer.phar install --ignore-platform-reqs'
|
||||
}
|
||||
}
|
||||
stage('PHP 8') {
|
||||
stage('PHP 8.1') {
|
||||
agent {
|
||||
docker {
|
||||
image 'php:8-cli-alpine'
|
||||
image 'php:8.1-cli-alpine'
|
||||
args '-u root --privileged'
|
||||
}
|
||||
}
|
||||
steps {
|
||||
sh 'apk add --no-cache git icu-dev'
|
||||
sh 'docker-php-ext-configure intl && docker-php-ext-install intl'
|
||||
sh 'php ./vendor/bin/phpunit --colors=never'
|
||||
}
|
||||
}
|
||||
stage('PHP 8.2') {
|
||||
agent {
|
||||
docker {
|
||||
image 'php:8.2-cli-alpine'
|
||||
args '-u root --privileged'
|
||||
}
|
||||
}
|
||||
@ -36,16 +49,6 @@ pipeline {
|
||||
sh 'php ./vendor/bin/phpunit --colors=never'
|
||||
}
|
||||
}
|
||||
stage('Code Cleanliness') {
|
||||
agent any
|
||||
steps {
|
||||
sh "php ./vendor/bin/phpstan analyse -c phpstan.neon -n --no-progress --no-ansi --error-format=checkstyle | awk '{\$1=\$1;print}' > build/logs/phpstan.log"
|
||||
recordIssues(
|
||||
failOnError: false,
|
||||
tools: [phpStan(reportEncoding: 'UTF-8', pattern: 'build/logs/phpstan.log')]
|
||||
)
|
||||
}
|
||||
}
|
||||
stage('Coverage') {
|
||||
agent any
|
||||
steps {
|
||||
|
12
README.md
12
README.md
@ -31,12 +31,18 @@ Update your anime/manga list on Kitsu.io and Anilist
|
||||
|
||||
### Requirements
|
||||
|
||||
* PHP 8
|
||||
* PDO SQLite or PDO PostgreSQL (For collection tab)
|
||||
* GD extension for caching images
|
||||
* PHP 8.2
|
||||
* ext-dom (For editing the DOM)
|
||||
* ext-gd (For caching images)
|
||||
* ext-intl (For time localization)
|
||||
* ext-json
|
||||
* ext-mbstring
|
||||
* ext-pdo
|
||||
|
||||
### Highly Recommended
|
||||
|
||||
* Redis or Memcached for caching
|
||||
* PDO SQLite or PDO PostgreSQL (For collection tab)
|
||||
|
||||
### Installation
|
||||
|
||||
|
@ -16,10 +16,10 @@
|
||||
|
||||
use const Aviat\AnimeClient\{
|
||||
ALPHA_SLUG_PATTERN,
|
||||
NUM_PATTERN,
|
||||
SLUG_PATTERN,
|
||||
DEFAULT_CONTROLLER,
|
||||
DEFAULT_CONTROLLER_METHOD,
|
||||
DEFAULT_CONTROLLER
|
||||
SLUG_PATTERN,
|
||||
NUM_PATTERN,
|
||||
};
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
@ -27,7 +27,7 @@ use const Aviat\AnimeClient\{
|
||||
//
|
||||
// Maps paths to controllers and methods
|
||||
// -------------------------------------------------------------------------
|
||||
$routes = [
|
||||
$base_routes = [
|
||||
// ---------------------------------------------------------------------
|
||||
// AJAX Routes
|
||||
// ---------------------------------------------------------------------
|
||||
@ -190,14 +190,14 @@ $routes = [
|
||||
'character' => [
|
||||
'path' => '/character/{slug}',
|
||||
'tokens' => [
|
||||
'slug' => SLUG_PATTERN
|
||||
]
|
||||
'slug' => SLUG_PATTERN,
|
||||
],
|
||||
],
|
||||
'person' => [
|
||||
'path' => '/people/{slug}',
|
||||
'tokens' => [
|
||||
'slug' => SLUG_PATTERN,
|
||||
]
|
||||
],
|
||||
],
|
||||
'default_user_info' => [
|
||||
'path' => '/me',
|
||||
@ -209,8 +209,8 @@ $routes = [
|
||||
'controller' => 'user',
|
||||
'action' => 'about',
|
||||
'tokens' => [
|
||||
'username' => '.*?'
|
||||
]
|
||||
'username' => '.*?',
|
||||
],
|
||||
],
|
||||
// ---------------------------------------------------------------------
|
||||
// Default / Shared routes
|
||||
@ -231,8 +231,8 @@ $routes = [
|
||||
'controller' => 'images',
|
||||
'tokens' => [
|
||||
'type' => SLUG_PATTERN,
|
||||
'file' => '[a-z0-9\-]+\.[a-z]{3,4}'
|
||||
]
|
||||
'file' => '[a-z0-9\-]+\.[a-z]{3,4}',
|
||||
],
|
||||
],
|
||||
'settings' => [
|
||||
'path' => '/settings',
|
||||
@ -259,8 +259,8 @@ $routes = [
|
||||
'controller' => 'history',
|
||||
'path' => '/history/{type}',
|
||||
'tokens' => [
|
||||
'type' => SLUG_PATTERN
|
||||
]
|
||||
'type' => SLUG_PATTERN,
|
||||
],
|
||||
],
|
||||
'increment' => [
|
||||
'path' => '/{controller}/increment',
|
||||
@ -291,7 +291,7 @@ $routes = [
|
||||
'action' => 'edit',
|
||||
'tokens' => [
|
||||
'id' => SLUG_PATTERN,
|
||||
'status' => '([a-zA-Z\-_]|%20)+',
|
||||
'status' => SLUG_PATTERN,
|
||||
],
|
||||
],
|
||||
'list' => [
|
||||
@ -314,15 +314,10 @@ $defaultMap = [
|
||||
'verb' => 'get',
|
||||
];
|
||||
|
||||
foreach ($routes as &$route)
|
||||
$routes = [];
|
||||
foreach ($base_routes as $name => $route)
|
||||
{
|
||||
foreach($defaultMap as $key => $val)
|
||||
{
|
||||
if ( ! array_key_exists($key, $route))
|
||||
{
|
||||
$route[$key] = $val;
|
||||
}
|
||||
}
|
||||
$routes[$name] = array_merge($defaultMap, $route);
|
||||
}
|
||||
|
||||
return $routes;
|
||||
|
@ -4,11 +4,9 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 8
|
||||
* PHP version 8.1
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @copyright 2015 - 2021 Timothy J. Warren
|
||||
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 5.2
|
||||
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
||||
@ -20,12 +18,10 @@ use Aura\Html\HelperLocatorFactory;
|
||||
use Aura\Router\RouterContainer;
|
||||
use Aura\Session\SessionFactory;
|
||||
use Aviat\AnimeClient\API\{Anilist, Kitsu};
|
||||
use Aviat\AnimeClient\Component;
|
||||
use Aviat\AnimeClient\Model;
|
||||
use Aviat\AnimeClient\{Component, Model};
|
||||
use Aviat\Banker\Teller;
|
||||
use Aviat\Ion\Config;
|
||||
use Aviat\Ion\Di\Container;
|
||||
use Aviat\Ion\Di\ContainerInterface;
|
||||
use Aviat\Ion\Di\{Container, ContainerInterface};
|
||||
use Laminas\Diactoros\ServerRequestFactory;
|
||||
use Monolog\Formatter\JsonFormatter;
|
||||
use Monolog\Handler\RotatingFileHandler;
|
||||
@ -77,15 +73,16 @@ return static function (array $configArray = []): Container {
|
||||
$container->set('cache', static function (ContainerInterface $container): CacheInterface {
|
||||
$logger = $container->getLogger();
|
||||
$config = $container->get('config')->get('cache');
|
||||
|
||||
return new Teller($config, $logger);
|
||||
});
|
||||
|
||||
// Create Aura Router Object
|
||||
$container->set('aura-router', static fn() => new RouterContainer);
|
||||
$container->set('aura-router', static fn () => new RouterContainer());
|
||||
|
||||
// Create Html helpers
|
||||
$container->set('html-helper', static function (ContainerInterface $container) {
|
||||
$htmlHelper = (new HelperLocatorFactory)->newInstance();
|
||||
$htmlHelper = (new HelperLocatorFactory())->newInstance();
|
||||
$helpers = [
|
||||
'menu' => Helper\Menu::class,
|
||||
'field' => Helper\Form::class,
|
||||
@ -95,8 +92,9 @@ return static function (array $configArray = []): Container {
|
||||
foreach ($helpers as $name => $class)
|
||||
{
|
||||
$htmlHelper->set($name, static function () use ($class, $container) {
|
||||
$helper = new $class;
|
||||
$helper = new $class();
|
||||
$helper->setContainer($container);
|
||||
|
||||
return $helper;
|
||||
});
|
||||
}
|
||||
@ -106,7 +104,7 @@ return static function (array $configArray = []): Container {
|
||||
|
||||
// Create Component helpers
|
||||
$container->set('component-helper', static function (ContainerInterface $container) {
|
||||
$helper = (new HelperLocatorFactory)->newInstance();
|
||||
$helper = (new HelperLocatorFactory())->newInstance();
|
||||
$components = [
|
||||
'animeCover' => Component\AnimeCover::class,
|
||||
'mangaCover' => Component\MangaCover::class,
|
||||
@ -119,8 +117,9 @@ return static function (array $configArray = []): Container {
|
||||
foreach ($components as $name => $componentClass)
|
||||
{
|
||||
$helper->set($name, static function () use ($container, $componentClass) {
|
||||
$helper = new $componentClass;
|
||||
$helper = new $componentClass();
|
||||
$helper->setContainer($container);
|
||||
|
||||
return $helper;
|
||||
});
|
||||
}
|
||||
@ -140,9 +139,6 @@ return static function (array $configArray = []): Container {
|
||||
// Create session Object
|
||||
$container->set('session', static fn () => (new SessionFactory())->newInstance($_COOKIE));
|
||||
|
||||
// Miscellaneous helper methods
|
||||
$container->set('util', static fn ($container) => new Util($container));
|
||||
|
||||
// Models
|
||||
$container->set('kitsu-model', static function (ContainerInterface $container): Kitsu\Model {
|
||||
$requestBuilder = new Kitsu\RequestBuilder($container);
|
||||
@ -158,6 +154,7 @@ return static function (array $configArray = []): Container {
|
||||
|
||||
$cache = $container->get('cache');
|
||||
$model->setCache($cache);
|
||||
|
||||
return $model;
|
||||
});
|
||||
$container->set('anilist-model', static function (ContainerInterface $container): Anilist\Model {
|
||||
@ -174,24 +171,27 @@ return static function (array $configArray = []): Container {
|
||||
|
||||
return $model;
|
||||
});
|
||||
$container->set('anime-model', static fn ($container) => new Model\Anime($container));
|
||||
$container->set('manga-model', static fn ($container) => new Model\Manga($container));
|
||||
$container->set('anime-collection-model', static fn ($container) => new Model\AnimeCollection($container));
|
||||
$container->set('manga-collection-model', static fn ($container) => new Model\MangaCollection($container));
|
||||
$container->set('settings-model', static function ($container) {
|
||||
$model = new Model\Settings($container->get('config'));
|
||||
$model->setContainer($container);
|
||||
|
||||
return $model;
|
||||
});
|
||||
|
||||
$container->setSimple('anime-model', Model\Anime::class);
|
||||
$container->setSimple('manga-model', Model\Manga::class);
|
||||
$container->setSimple('anime-collection-model', Model\AnimeCollection::class);
|
||||
|
||||
// Miscellaneous Classes
|
||||
$container->set('auth', static fn ($container) => new Kitsu\Auth($container));
|
||||
$container->set('url-generator', static fn ($container) => new UrlGenerator($container));
|
||||
$container->setSimple('util', Util::class);
|
||||
$container->setSimple('auth', Kitsu\Auth::class);
|
||||
$container->setSimple('url-generator', UrlGenerator::class);
|
||||
$container->setSimple('render-helper', RenderHelper::class);
|
||||
|
||||
// -------------------------------------------------------------------------
|
||||
// Dispatcher
|
||||
// -------------------------------------------------------------------------
|
||||
$container->set('dispatcher', static fn ($container) => new Dispatcher($container));
|
||||
$container->setSimple('dispatcher', Dispatcher::class);
|
||||
|
||||
return $container;
|
||||
};
|
||||
|
6
app/config/anilist.toml.example
Normal file
6
app/config/anilist.toml.example
Normal file
@ -0,0 +1,6 @@
|
||||
################################################################################
|
||||
# Anilist API #
|
||||
################################################################################
|
||||
client_id = "your_client_id"
|
||||
client_secret = "your_client_secret"
|
||||
username = "user123"
|
@ -14,6 +14,9 @@ show_anime_collection = true
|
||||
# do you wish to show the manga collection?
|
||||
show_manga_collection = false
|
||||
|
||||
# what theme would you like to use? light, dark, or auto
|
||||
theme = "auto"
|
||||
|
||||
################################################################################
|
||||
# Default views and paths
|
||||
################################################################################
|
||||
|
0
app/logs/.gitkeep
Normal file → Executable file
0
app/logs/.gitkeep
Normal file → Executable file
@ -1,15 +1,16 @@
|
||||
<article
|
||||
class="media"
|
||||
data-kitsu-id="<?= $item['id'] ?>"
|
||||
data-anilist-id="<?= $item['anilist_id'] ?>"
|
||||
data-mal-id="<?= $item['mal_id'] ?>"
|
||||
>
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<button title="Increment episode count" class="plus-one" hidden>+1 Episode</button>
|
||||
<?php endif ?>
|
||||
<?= $helper->picture("images/anime/{$item['anime']['id']}.webp") ?>
|
||||
<?= $_->h->img($item['anime']['cover_image'], ['width' => 220, 'loading' => 'lazy']) ?>
|
||||
|
||||
<div class="name">
|
||||
<a href="<?= $url->generate('anime.details', ['id' => $item['anime']['slug']]) ?>">
|
||||
<a href="<?= $_->urlFromRoute('anime.details', ['id' => $item['anime']['slug']]) ?>">
|
||||
<span class="canonical"><?= $item['anime']['title'] ?></span>
|
||||
<?php foreach ($item['anime']['titles'] as $title): ?>
|
||||
<br/>
|
||||
@ -49,7 +50,7 @@
|
||||
<?php if ($link['meta']['link']): ?>
|
||||
<a href="<?= $link['link'] ?>"
|
||||
title="Stream '<?= $item['anime']['title'] ?>' on <?= $link['meta']['name'] ?>">
|
||||
<?= $helper->img("/public/images/{$link['meta']['image']}", [
|
||||
<?= $_->h->img("/public/images/{$link['meta']['image']}", [
|
||||
'class' => 'streaming-logo',
|
||||
'width' => 20,
|
||||
'height' => 20,
|
||||
@ -57,7 +58,7 @@
|
||||
]); ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<?= $helper->img("/public/images/{$link['meta']['image']}", [
|
||||
<?= $_->h->img("/public/images/{$link['meta']['image']}", [
|
||||
'class' => 'streaming-logo',
|
||||
'width' => 20,
|
||||
'height' => 20,
|
||||
@ -69,11 +70,11 @@
|
||||
</div>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed" title="Edit information about this anime" href="<?=
|
||||
$url->generate('edit', [
|
||||
$_->urlFromRoute('edit', [
|
||||
'controller' => 'anime',
|
||||
'id' => $item['id'],
|
||||
'status' => $item['watching_status']
|
||||
@ -91,9 +92,9 @@
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="media_type"><?= $escape->html($item['anime']['show_type']) ?></div>
|
||||
<div class="airing-status"><?= $escape->html($item['airing']['status']) ?></div>
|
||||
<div class="age-rating"><?= $escape->html($item['anime']['age_rating']) ?></div>
|
||||
<div class="media_type"><?= $_->escape->html($item['anime']['show_type']) ?></div>
|
||||
<div class="airing-status"><?= $_->escape->html($item['airing']['status']) ?></div>
|
||||
<div class="age-rating"><?= $_->escape->html($item['anime']['age_rating']) ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
@ -1,26 +1,25 @@
|
||||
<article class="media" data-kitsu-id="<?= $item['id'] ?>" data-mal-id="<?= $item['mal_id'] ?>">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<div class="edit-buttons" hidden>
|
||||
<button class="plus-one-chapter">+1 Chapter</button>
|
||||
<?php /* <button class="plus-one-volume">+1 Volume</button> */ ?>
|
||||
</div>
|
||||
<?php endif ?>
|
||||
<?= $helper->picture("images/manga/{$item['manga']['id']}.webp") ?>
|
||||
<?= $_->h->img($item['manga']['image'], ['width' => 220, 'loading' => 'lazy']) ?>
|
||||
<div class="name">
|
||||
<a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>">
|
||||
<?= $escape->html($item['manga']['title']) ?>
|
||||
<a href="<?= $_->urlFromRoute('manga.details', ['id' => $item['manga']['slug']]) ?>">
|
||||
<?= $_->escape->html($item['manga']['title']) ?>
|
||||
<?php foreach($item['manga']['titles'] as $title): ?>
|
||||
<br /><small><?= $title ?></small>
|
||||
<?php endforeach ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="table">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed"
|
||||
title="Edit information about this manga"
|
||||
href="<?= $url->generate('edit', [
|
||||
href="<?= $_->urlFromRoute('edit', [
|
||||
'controller' => 'manga',
|
||||
'id' => $item['id'],
|
||||
'status' => $name
|
||||
@ -64,11 +63,6 @@
|
||||
Chapters: <span class="chapters_read"><?= $item['chapters']['read'] ?></span> /
|
||||
<span class="chapter_count"><?= $item['chapters']['total'] ?></span>
|
||||
</div>
|
||||
<?php /* </div>
|
||||
<div class="row"> */ ?>
|
||||
<div class="volume_completion">
|
||||
Volumes: <span class="volume_count"><?= $item['volumes']['total'] ?></span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
@ -1,4 +1,4 @@
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<main>
|
||||
<h2>Add Anime to your List</h2>
|
||||
<form action="<?= $action_url ?>" method="post">
|
||||
|
@ -1,6 +1,6 @@
|
||||
<main class="media-list">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate('anime.add.get') ?>">Add Item</a>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute('anime.add.get') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
@ -11,16 +11,16 @@
|
||||
<?php foreach ($sections as $name => $items): ?>
|
||||
<?php if (empty($items)): ?>
|
||||
<section class="status">
|
||||
<h2><?= $escape->html($name) ?></h2>
|
||||
<h2><?= $_->escape->html($name) ?></h2>
|
||||
<h3>There's nothing here!</h3>
|
||||
</section>
|
||||
<?php else: ?>
|
||||
<section class="status">
|
||||
<h2><?= $escape->html($name) ?></h2>
|
||||
<h2><?= $_->escape->html($name) ?></h2>
|
||||
<section class="media-wrap">
|
||||
<?php foreach($items as $item): ?>
|
||||
<?php if ($item['private'] && ! $auth->isAuthenticated()) continue; ?>
|
||||
<?= $component->animeCover($item) ?>
|
||||
<?php if ($item['private'] && ! $_->isAuthenticated()) continue; ?>
|
||||
<?= $_->component->animeCover($item) ?>
|
||||
<?php endforeach ?>
|
||||
</section>
|
||||
</section>
|
||||
|
@ -1,13 +1,12 @@
|
||||
<?php
|
||||
|
||||
use Aviat\AnimeClient\Kitsu;
|
||||
use function Aviat\AnimeClient\getLocalImg;
|
||||
use function Aviat\AnimeClient\friendlyTime;
|
||||
|
||||
?>
|
||||
<main class="details fixed">
|
||||
<section class="flex" unselectable>
|
||||
<section class="flex">
|
||||
<aside class="info">
|
||||
<?= $helper->picture("images/anime/{$data['id']}-original.webp") ?>
|
||||
<?= $_->h->img($data['cover_image'], ['width' => '390']) ?>
|
||||
|
||||
<br />
|
||||
|
||||
@ -17,6 +16,13 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<td><?= $data['status'] ?></td>
|
||||
</tr>
|
||||
|
||||
<?php if ( ! empty($data['airDate'])): ?>
|
||||
<tr>
|
||||
<td>Original Airing</td>
|
||||
<td><?= $data['airDate'] ?></td>
|
||||
</tr>
|
||||
<?php endif ?>
|
||||
|
||||
<tr>
|
||||
<td>Show Type</td>
|
||||
<td><?= (strlen($data['show_type']) > 3) ? ucfirst(strtolower($data['show_type'])) : $data['show_type'] ?></td>
|
||||
@ -32,14 +38,14 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<?php if (( ! empty($data['episode_length'])) && $data['episode_count'] !== 1): ?>
|
||||
<tr>
|
||||
<td>Episode Length</td>
|
||||
<td><?= Kitsu::friendlyTime($data['episode_length']) ?></td>
|
||||
<td><?= friendlyTime($data['episode_length']) ?></td>
|
||||
</tr>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if (isset($data['total_length'], $data['episode_count']) && $data['total_length'] > 0): ?>
|
||||
<tr>
|
||||
<td>Total Length</td>
|
||||
<td><?= Kitsu::friendlyTime($data['total_length']) ?></td>
|
||||
<td><?= friendlyTime($data['total_length']) ?></td>
|
||||
</tr>
|
||||
<?php endif ?>
|
||||
|
||||
@ -104,7 +110,7 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
href="<?= $link['link'] ?>"
|
||||
title="Stream '<?= $data['title'] ?>' on <?= $link['meta']['name'] ?>"
|
||||
>
|
||||
<?= $helper->img("/public/images/{$link['meta']['image']}", [
|
||||
<?= $_->h->img("/public/images/{$link['meta']['image']}", [
|
||||
'class' => 'streaming-logo',
|
||||
'width' => 50,
|
||||
'height' => 50,
|
||||
@ -113,7 +119,7 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<?= $link['meta']['name'] ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<?= $helper->img("/public/images/{$link['meta']['image']}", [
|
||||
<?= $_->h->img("/public/images/{$link['meta']['image']}", [
|
||||
'class' => 'streaming-logo',
|
||||
'width' => 50,
|
||||
'height' => 50,
|
||||
@ -122,8 +128,8 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<?= $link['meta']['name'] ?>
|
||||
<?php endif ?>
|
||||
</td>
|
||||
<td><?= implode(', ', $link['subs']) ?></td>
|
||||
<td><?= implode(', ', $link['dubs']) ?></td>
|
||||
<td><?= implode(', ', array_map(fn ($sub) => Locale::getDisplayLanguage($sub, 'en'), $link['subs'])) ?></td>
|
||||
<td><?= implode(', ', array_map(fn ($dub) => Locale::getDisplayLanguage($dub, 'en'), $link['dubs'])) ?></td>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
@ -151,18 +157,18 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<section>
|
||||
<h2>Characters</h2>
|
||||
|
||||
<?= $component->tabs('character-types', $data['characters'], static function ($characterList, $role)
|
||||
use ($component, $url, $helper) {
|
||||
<?= $_->component->tabs('character-types', $data['characters'], static function ($characterList, $role)
|
||||
use ($_) {
|
||||
$rendered = [];
|
||||
foreach ($characterList as $id => $character):
|
||||
if (empty($character['image']['original']))
|
||||
if (empty($character['image']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$rendered[] = $component->character(
|
||||
$rendered[] = $_->component->character(
|
||||
$character['name'],
|
||||
$url->generate('character', ['slug' => $character['slug']]),
|
||||
$helper->picture("images/characters/{$id}.webp"),
|
||||
$_->urlFromRoute('character', ['slug' => $character['slug']]),
|
||||
$_->h->img($character['image']),
|
||||
(strtolower($role) !== 'main') ? 'small-character' : 'character'
|
||||
);
|
||||
endforeach;
|
||||
@ -176,18 +182,18 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<section>
|
||||
<h2>Staff</h2>
|
||||
|
||||
<?= $component->verticalTabs('staff-role', $data['staff'], static function ($staffList)
|
||||
use ($component, $url, $helper) {
|
||||
<?= $_->component->verticalTabs('staff-role', $data['staff'], static function ($staffList)
|
||||
use ($_) {
|
||||
$rendered = [];
|
||||
foreach ($staffList as $id => $person):
|
||||
if (empty($person['image']['original']))
|
||||
if (empty($person['image']))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
$rendered[] = $component->character(
|
||||
$rendered[] = $_ ->component->character(
|
||||
$person['name'],
|
||||
$url->generate('person', ['slug' => $person['slug']]),
|
||||
$helper->picture(getLocalImg($person['image']['original'] ?? NULL)),
|
||||
$_->urlFromRoute('person', ['slug' => $person['slug']]),
|
||||
$_->h->img($person['image']),
|
||||
'character small-person',
|
||||
);
|
||||
endforeach;
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<main>
|
||||
<h2>Edit Anime List Item</h2>
|
||||
<form action="<?= $action ?>" method="post">
|
||||
@ -6,9 +6,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<h3><?= $escape->html($item['anime']['title']) ?></h3>
|
||||
<h3><?= $_->escape->html($item['anime']['title']) ?></h3>
|
||||
<?php foreach($item['anime']['titles'] as $title): ?>
|
||||
<h4><?= $escape->html($title) ?></h4>
|
||||
<h4><?= $_->escape->html($title) ?></h4>
|
||||
<?php endforeach ?>
|
||||
</th>
|
||||
</tr>
|
||||
@ -16,7 +16,7 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="9">
|
||||
<?= $helper->picture("images/anime/{$item['anime']['id']}-original.webp", "jpg", [], ["width" => "390"]) ?>
|
||||
<?= $_->h->img($item['anime']['cover_image']) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -70,7 +70,7 @@
|
||||
<tr>
|
||||
<td><label for="notes">Notes</label></td>
|
||||
<td>
|
||||
<textarea name="notes" id="notes"><?= $escape->html($item['notes']) ?></textarea>
|
||||
<textarea name="notes" id="notes"><?= $_->escape->html($item['notes']) ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -87,7 +87,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<form class="js-delete" action="<?= $url->generate('anime.delete') ?>" method="post">
|
||||
<form class="js-delete" action="<?= $_->urlFromRoute('anime.delete') ?>" method="post">
|
||||
<fieldset>
|
||||
<legend>Danger Zone</legend>
|
||||
<table class="form invisible">
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php use function Aviat\AnimeClient\colNotEmpty; ?>
|
||||
<main class="media-list">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate('anime.add.get') ?>">Add Item</a>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute('anime.add.get') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
@ -20,26 +20,26 @@
|
||||
<table class='media-wrap'>
|
||||
<thead>
|
||||
<tr>
|
||||
<?php if($auth->isAuthenticated()): ?>
|
||||
<?php if($_->isAuthenticated()): ?>
|
||||
<td class="no-border"> </td>
|
||||
<?php endif ?>
|
||||
<th>Title</th>
|
||||
<th>Airing Status</th>
|
||||
<th>Score</th>
|
||||
<th class='numeric'>Score</th>
|
||||
<th>Type</th>
|
||||
<th>Progress</th>
|
||||
<th>Rated</th>
|
||||
<th class='numeric'>Progress</th>
|
||||
<th class='rating'>Age Rating</th>
|
||||
<th>Attributes</th>
|
||||
<?php if($hasNotes): ?><th>Notes</th><?php endif ?>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach($items as $item): ?>
|
||||
<?php if ($item['private'] && ! $auth->isAuthenticated()) continue; ?>
|
||||
<?php if ($item['private'] && ! $_->isAuthenticated()) continue; ?>
|
||||
<tr id="a-<?= $item['id'] ?>">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<td>
|
||||
<a class="bracketed" href="<?= $url->generate('edit', [
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute('edit', [
|
||||
'controller' => 'anime',
|
||||
'id' => $item['id'],
|
||||
'status' => $item['watching_status']
|
||||
@ -47,7 +47,7 @@
|
||||
</td>
|
||||
<?php endif ?>
|
||||
<td class="align-left justify">
|
||||
<a href="<?= $url->generate('anime.details', ['id' => $item['anime']['slug']]) ?>">
|
||||
<a href="<?= $_->urlFromRoute('anime.details', ['id' => $item['anime']['slug']]) ?>">
|
||||
<?= $item['anime']['title'] ?>
|
||||
</a>
|
||||
<br />
|
||||
@ -65,7 +65,7 @@
|
||||
<?php foreach($item['anime']['streaming_links'] as $link): ?>
|
||||
<?php if ($link['meta']['link'] !== FALSE): ?>
|
||||
<a href="<?= $link['link'] ?>" title="Stream '<?= $item['anime']['title'] ?>' on <?= $link['meta']['name'] ?>">
|
||||
<?= $helper->img("/public/images/{$link['meta']['image']}", [
|
||||
<?= $_->h->img("/public/images/{$link['meta']['image']}", [
|
||||
'class' => 'small-streaming-logo',
|
||||
'width' => 25,
|
||||
'height' => 25,
|
||||
@ -73,7 +73,7 @@
|
||||
]) ?>
|
||||
</a>
|
||||
<?php else: ?>
|
||||
<?= $helper->img("/public/images/{$link['meta']['image']}", [
|
||||
<?= $_->h->img("/public/images/{$link['meta']['image']}", [
|
||||
'class' => 'small-streaming-logo',
|
||||
'width' => 25,
|
||||
'height' => 25,
|
||||
@ -101,7 +101,7 @@
|
||||
<?php endforeach ?>
|
||||
</ul>
|
||||
</td>
|
||||
<?php if ($hasNotes): ?><td><p><?= $escape->html($item['notes']) ?></p></td><?php endif ?>
|
||||
<?php if ($hasNotes): ?><td><p><?= $_->escape->html($item['notes']) ?></p></td><?php endif ?>
|
||||
</tr>
|
||||
<?php endforeach ?>
|
||||
</tbody>
|
||||
@ -110,4 +110,4 @@
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<script defer="defer" src="<?= $urlGenerator->assetUrl('js/tables.min.js') ?>"></script>
|
||||
<script defer="defer" src="<?= $_->assetUrl('js/tables.min.js') ?>"></script>
|
@ -7,7 +7,7 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<main class="character-page details fixed">
|
||||
<section class="flex flex-no-wrap">
|
||||
<aside>
|
||||
<?= $helper->picture("images/characters/{$data['id']}-original.webp") ?>
|
||||
<?= $_->h->img($data['image']) ?>
|
||||
</aside>
|
||||
<div>
|
||||
<h2 class="toph"><?= $data['name'] ?></h2>
|
||||
@ -26,7 +26,7 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<br />
|
||||
<hr />
|
||||
<div class="description">
|
||||
<p><?= str_replace("\n", '</p><p>', $data['description']) ?></p>
|
||||
<p><?= nl2br($data['description']) ?></p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@ -34,14 +34,14 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<?php if ( ! (empty($data['media']['anime']) || empty($data['media']['manga']))): ?>
|
||||
<h3>Media</h3>
|
||||
|
||||
<?= $component->tabs('character-media', $data['media'], static function ($media, $mediaType) use ($url, $component, $helper) {
|
||||
<?= $_->component->tabs('character-media', $data['media'], static function ($media, $mediaType) use ($_) {
|
||||
$rendered = [];
|
||||
foreach ($media as $id => $item)
|
||||
{
|
||||
$rendered[] = $component->media(
|
||||
$rendered[] = $_->component->media(
|
||||
array_merge([$item['title']], $item['titles']),
|
||||
$url->generate("{$mediaType}.details", ['id' => $item['slug']]),
|
||||
$helper->picture("images/{$mediaType}/{$item['id']}.webp")
|
||||
$_->urlFromRoute("{$mediaType}.details", ['id' => $item['slug']]),
|
||||
$_->h->img(Kitsu::getPosterImage($item), ['width' => 220, 'loading' => 'lazy']),
|
||||
);
|
||||
}
|
||||
|
||||
@ -72,10 +72,10 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<td>
|
||||
<article class="character">
|
||||
<?php
|
||||
$link = $url->generate('person', ['id' => $c['person']['id']]);
|
||||
$link = $_->urlFromRoute('person', ['id' => $c['person']['id']]);
|
||||
?>
|
||||
<a href="<?= $link ?>">
|
||||
<?= $helper->picture(getLocalImg($c['person']['image'], TRUE)) ?>
|
||||
<?= $_->h->img($c['person']['image']) ?>
|
||||
<div class="name">
|
||||
<?= $c['person']['name'] ?>
|
||||
</div>
|
||||
@ -87,11 +87,11 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<?php foreach ($c['series'] as $series): ?>
|
||||
<article class="media">
|
||||
<?php
|
||||
$link = $url->generate('anime.details', ['id' => $series['attributes']['slug']]);
|
||||
$link = $_->urlFromRoute('anime.details', ['id' => $series['attributes']['slug']]);
|
||||
$titles = Kitsu::filterTitles($series['attributes']);
|
||||
?>
|
||||
<a href="<?= $link ?>">
|
||||
<?= $helper->picture(getLocalImg($series['attributes']['posterImage']['small'], TRUE)) ?>
|
||||
<?= $_->h->img(Kitsu::getPosterImage($series['attributes'])) ?>
|
||||
</a>
|
||||
<div class="name">
|
||||
<a href="<?= $link ?>">
|
||||
@ -115,18 +115,18 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<?php if ( ! empty($vas)): ?>
|
||||
<h4>Voice Actors</h4>
|
||||
|
||||
<?= $component->tabs('character-vas', $vas, static function ($casting) use ($url, $component, $helper) {
|
||||
<?= $_->component->tabs('character-vas', $vas, static function ($casting) use ($_) {
|
||||
$castings = [];
|
||||
foreach ($casting as $id => $c):
|
||||
$person = $component->character(
|
||||
$person = $_->component->character(
|
||||
$c['person']['name'],
|
||||
$url->generate('person', ['slug' => $c['person']['slug']]),
|
||||
$helper->picture(getLocalImg($c['person']['image']))
|
||||
$_->urlFromRoute('person', ['slug' => $c['person']['slug']]),
|
||||
$_->h->img($c['person']['image']['original']['url']),
|
||||
);
|
||||
$medias = array_map(fn ($series) => $component->media(
|
||||
$medias = array_map(fn ($series) => $_->component->media(
|
||||
array_merge([$series['title']], $series['titles']),
|
||||
$url->generate('anime.details', ['id' => $series['slug']]),
|
||||
$helper->picture(getLocalImg($series['posterImage'], TRUE))
|
||||
$_->urlFromRoute('anime.details', ['id' => $series['slug']]),
|
||||
$_->h->img(Kitsu::getPosterImage($series)),
|
||||
), $c['series']);
|
||||
$media = implode('', array_map('mb_trim', $medias));
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<main>
|
||||
<h2>Add <?= ucfirst($collection_type) ?> to your Collection</h2>
|
||||
<form action="<?= $action_url ?>" method="post">
|
||||
@ -9,7 +9,7 @@
|
||||
<div class="cssload-inner cssload-two"></div>
|
||||
<div class="cssload-inner cssload-three"></div>
|
||||
</div>
|
||||
<label for="search">Search for <?= $collection_type ?> by name: <input type="search" id="search" name="search" /></label>
|
||||
<label for="search-anime-collection">Search for <?= $collection_type ?> by name: <input type="search" id="search-anime-collection" name="search" /></label>
|
||||
<section id="series-list" class="media-wrap">
|
||||
</section>
|
||||
</section>
|
||||
|
@ -1,17 +1,17 @@
|
||||
<article class="media" id="a-<?= $item['hummingbird_id'] ?>">
|
||||
<?= $helper->picture("images/anime/{$item['hummingbird_id']}.webp") ?>
|
||||
<?= $_->h->picture("images/anime/{$item['hummingbird_id']}.webp") ?>
|
||||
<div class="name">
|
||||
<a href="<?= $url->generate('anime.details', ['id' => $item['slug']]) ?>">
|
||||
<a href="<?= $_->urlFromRoute('anime.details', ['id' => $item['slug']]) ?>">
|
||||
<?= $item['title'] ?>
|
||||
<?= ($item['alternate_title'] != "") ? "<small><br />{$item['alternate_title']}</small>" : ""; ?>
|
||||
</a>
|
||||
</div>
|
||||
<div class="table">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed"
|
||||
href="<?= $url->generate($collection_type . '.collection.edit.get', [
|
||||
href="<?= $_->urlFromRoute($collection_type . '.collection.edit.get', [
|
||||
'id' => $item['hummingbird_id']
|
||||
]) ?>">Edit</a>
|
||||
</span>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<?php use function Aviat\AnimeClient\renderTemplate; ?>
|
||||
<main class="media-list">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute($collection_type . '.collection.add.get') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
@ -9,16 +9,14 @@
|
||||
<br />
|
||||
<label>Filter: <input type='text' class='media-filter' /></label>
|
||||
<br />
|
||||
<?= $component->tabs('collection-tab', $sections, static function ($items) use ($auth, $collection_type, $helper, $url, $component) {
|
||||
<?= $_->component->tabs('collection-tab', $sections, static function ($items) use ($_, $collection_type) {
|
||||
$rendered = [];
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$rendered[] = renderTemplate(__DIR__ . '/cover-item.php', [
|
||||
'auth' => $auth,
|
||||
'_' => $_,
|
||||
'collection_type' => $collection_type,
|
||||
'helper' => $helper,
|
||||
'item' => $item,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
<?php use function Aviat\AnimeClient\renderTemplate ?>
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<main>
|
||||
<h2>Edit Anime Collection Item</h2>
|
||||
<form action="<?= $action_url ?>" method="post">
|
||||
@ -7,7 +7,7 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="6" class="align-center">
|
||||
<?= $helper->picture("images/anime/{$item['hummingbird_id']}-original.webp", "jpg", [], ["width" => "390"]) ?>
|
||||
<?= $_->h->picture("images/anime/{$item['hummingbird_id']}-original.webp", "jpg", [], ["width" => "390"]) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -30,7 +30,7 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="notes">Notes</label></td>
|
||||
<td><textarea id="notes" name="notes"><?= $escape->html($item['notes']) ?></textarea></td>
|
||||
<td><textarea id="notes" name="notes"><?= $_->escape->html($item['notes']) ?></textarea></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td> </td>
|
||||
@ -44,7 +44,7 @@
|
||||
</tbody>
|
||||
</table>
|
||||
</form>
|
||||
<form class="js-delete" action="<?= $url->generate($collection_type . '.collection.delete') ?>" method="post">
|
||||
<form class="js-delete" action="<?= $_->urlFromRoute($collection_type . '.collection.delete') ?>" method="post">
|
||||
<fieldset>
|
||||
<legend>Danger Zone</legend>
|
||||
<table class="form invisible">
|
||||
|
@ -1,12 +1,12 @@
|
||||
<tr>
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<td>
|
||||
<a class="bracketed"
|
||||
href="<?= $url->generate($collection_type . '.collection.edit.get', ['id' => $item['hummingbird_id']]) ?>">Edit</a>
|
||||
href="<?= $_->urlFromRoute($collection_type . '.collection.edit.get', ['id' => $item['hummingbird_id']]) ?>">Edit</a>
|
||||
</td>
|
||||
<?php endif ?>
|
||||
<td class="align-left">
|
||||
<a href="<?= $url->generate('anime.details', ['id' => $item['slug']]) ?>">
|
||||
<a href="<?= $_->urlFromRoute('anime.details', ['id' => $item['slug']]) ?>">
|
||||
<?= $item['title'] ?>
|
||||
</a>
|
||||
<?= ! empty($item['alternate_title']) ? ' <br /><small> ' . $item['alternate_title'] . '</small>' : '' ?>
|
||||
@ -18,6 +18,6 @@
|
||||
<td><?= $item['episode_length'] ?></td>
|
||||
<td><?= $item['show_type'] ?></td>
|
||||
<td><?= $item['age_rating'] ?></td>
|
||||
<?php if ($hasNotes): ?><td class="align-left"><?= nl2br($item['notes'], TRUE) ?></td><?php endif ?>
|
||||
<?php if ($hasNotes): ?><td class="align-left"><?= nl2br($item['notes'] ?? '', TRUE) ?></td><?php endif ?>
|
||||
<td class="align-left"><?= implode(', ', $item['genres']) ?></td>
|
||||
</tr>
|
@ -1,7 +1,7 @@
|
||||
<?php use function Aviat\AnimeClient\{colNotEmpty, renderTemplate}; ?>
|
||||
<main>
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate($collection_type . '.collection.add.get') ?>">Add Item</a>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute($collection_type . '.collection.add.get') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
@ -9,10 +9,10 @@
|
||||
<br />
|
||||
<label>Filter: <input type='text' class='media-filter' /></label>
|
||||
<br />
|
||||
<?= $component->tabs('collection-tab', $sections, static function ($items, $section) use ($auth, $helper, $url, $collection_type) {
|
||||
<?= $_->component->tabs('collection-tab', $sections, static function ($items, $section) use ($_, $helper, $collection_type) {
|
||||
$hasNotes = colNotEmpty($items, 'notes');
|
||||
$hasMedia = $section === 'All';
|
||||
$firstTh = ($auth->isAuthenticated()) ? '<td> </td>' : '';
|
||||
$firstTh = ($_->isAuthenticated()) ? '<td> </td>' : '';
|
||||
$mediaTh = ($hasMedia) ? '<th>Media</th>' : '';
|
||||
$noteTh = ($hasNotes) ? '<th>Notes</th>' : '';
|
||||
|
||||
@ -20,13 +20,12 @@
|
||||
foreach ($items as $item)
|
||||
{
|
||||
$rendered[] = renderTemplate(__DIR__ . '/list-item.php', [
|
||||
'auth' => $auth,
|
||||
'_' => $_,
|
||||
'collection_type' => $collection_type,
|
||||
'hasMedia' => $hasMedia,
|
||||
'hasNotes' => $hasNotes,
|
||||
'helper' => $helper,
|
||||
'item' => $item,
|
||||
'url' => $url,
|
||||
]);
|
||||
}
|
||||
$rows = implode('', array_map('mb_trim', $rendered));
|
||||
@ -38,10 +37,10 @@
|
||||
{$firstTh}
|
||||
<th>Title</th>
|
||||
{$mediaTh}
|
||||
<th>Episode Count</th>
|
||||
<th>Episode Length</th>
|
||||
<th class='numeric'>Episode Count</th>
|
||||
<th class='numeric'>Episode Length</th>
|
||||
<th>Show Type</th>
|
||||
<th>Age Rating</th>
|
||||
<th class='rating'>Age Rating</th>
|
||||
{$noteTh}
|
||||
<th>Genres</th>
|
||||
</tr>
|
||||
@ -53,4 +52,4 @@ HTML;
|
||||
}) ?>
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<script defer="defer" src="<?= $urlGenerator->assetUrl('js/tables.min.js') ?>"></script>
|
||||
<script defer="defer" src="<?= $_->assetUrl('js/tables.min.js') ?>"></script>
|
@ -11,6 +11,6 @@
|
||||
</div>
|
||||
</section>
|
||||
<script nomodule="nomodule" src="https://polyfill.io/v3/polyfill.min.js?features=es5%2CObject.assign"></script>
|
||||
<script async="async" defer="defer" src="<?= $urlGenerator->assetUrl('js/scripts.min.js') ?>"></script>
|
||||
<script async="async" defer="defer" src="<?= $_->assetUrl('js/scripts.min.js') ?>"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
@ -6,25 +6,25 @@
|
||||
<meta http-equiv="cache-control" content="no-store" />
|
||||
<meta http-equiv="Content-Security-Policy" content="script-src 'self'" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=1" />
|
||||
<link rel="stylesheet" href="<?= $urlGenerator->assetUrl('css/' . $config->get('theme') . '.min.css') ?>" />
|
||||
<link rel="<?= $config->get('theme') === 'dark' ? '' : 'alternate ' ?>stylesheet" title="Dark Theme" href="<?= $urlGenerator->assetUrl('css/dark.min.css') ?>" />
|
||||
<link rel="icon" href="<?= $urlGenerator->assetUrl('images/icons/favicon.ico') ?>" />
|
||||
<link rel="apple-touch-icon" sizes="57x57" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-57x57.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="60x60" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-60x60.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="72x72" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-72x72.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="76x76" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-76x76.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="114x114" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-114x114.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="120x120" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-120x120.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="144x144" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-144x144.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="152x152" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-152x152.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="<?= $urlGenerator->assetUrl('images/icons/apple-icon-180x180.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="<?= $urlGenerator->assetUrl('images/icons/android-icon-192x192.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="<?= $urlGenerator->assetUrl('images/icons/favicon-32x32.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="96x96" href="<?= $urlGenerator->assetUrl('images/icons/favicon-96x96.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="<?= $urlGenerator->assetUrl('images/icons/favicon-16x16.png') ?>">
|
||||
<link rel="stylesheet" href="<?= $_->assetUrl('css/' . $_->config->get('theme') . '.min.css') ?>" />
|
||||
<link rel="<?= $_->config->get('theme') === 'dark' ? '' : 'alternate ' ?>stylesheet" title="Dark Theme" href="<?= $_->assetUrl('css/dark.min.css') ?>" />
|
||||
<link rel="icon" href="<?= $_->assetUrl('images/icons/favicon.ico') ?>" />
|
||||
<link rel="apple-touch-icon" sizes="57x57" href="<?= $_->assetUrl('images/icons/apple-icon-57x57.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="60x60" href="<?= $_->assetUrl('images/icons/apple-icon-60x60.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="72x72" href="<?= $_->assetUrl('images/icons/apple-icon-72x72.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="76x76" href="<?= $_->assetUrl('images/icons/apple-icon-76x76.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="114x114" href="<?= $_->assetUrl('images/icons/apple-icon-114x114.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="120x120" href="<?= $_->assetUrl('images/icons/apple-icon-120x120.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="144x144" href="<?= $_->assetUrl('images/icons/apple-icon-144x144.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="152x152" href="<?= $_->assetUrl('images/icons/apple-icon-152x152.png') ?>">
|
||||
<link rel="apple-touch-icon" sizes="180x180" href="<?= $_->assetUrl('images/icons/apple-icon-180x180.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="192x192" href="<?= $_->assetUrl('images/icons/android-icon-192x192.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="32x32" href="<?= $_->assetUrl('images/icons/favicon-32x32.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="96x96" href="<?= $_->assetUrl('images/icons/favicon-96x96.png') ?>">
|
||||
<link rel="icon" type="image/png" sizes="16x16" href="<?= $_->assetUrl('images/icons/favicon-16x16.png') ?>">
|
||||
|
||||
</head>
|
||||
<body class="<?= $escape->attr($url_type) ?> list">
|
||||
<body class="<?= $_->escape->attr($url_type) ?> list">
|
||||
<?php include 'setup-check.php' ?>
|
||||
<header>
|
||||
<?php
|
||||
|
@ -7,16 +7,14 @@
|
||||
<article class="flex flex-no-wrap flex-justify-start">
|
||||
<section class="flex-self-center history-img">
|
||||
<a href="<?= $item['url'] ?>">
|
||||
<?= $helper->picture(
|
||||
<?= $_->h->img(
|
||||
$item['coverImg'],
|
||||
'jpg',
|
||||
['width' => '110px', 'height' => '156px'],
|
||||
['width' => '110px', 'height' => '156px']
|
||||
) ?>
|
||||
</a>
|
||||
</section>
|
||||
<section class="flex-self-center">
|
||||
<?= $helper->a($item['url'], $item['title']) ?>
|
||||
<?= $_->h->a($item['url'], $item['title']) ?>
|
||||
<br />
|
||||
<br />
|
||||
<?= $item['action'] ?>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<main>
|
||||
<h2><?= $config->get('whose_list'); ?>'s Login</h2>
|
||||
<h2><?= $_->config->get('whose_list'); ?>'s Login</h2>
|
||||
<?= $message ?>
|
||||
<form method="post" action="<?= $url->generate('login.post') ?>">
|
||||
<form method="post" action="<?= $_->urlFromRoute('login.post') ?>">
|
||||
<table class="form invisible">
|
||||
<tr>
|
||||
<td><label for="password">Password: </label></td>
|
||||
|
@ -1,9 +1,21 @@
|
||||
<?php declare(strict_types=1);
|
||||
/**
|
||||
* Hummingbird Anime List Client
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 8.1
|
||||
*
|
||||
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 5.2
|
||||
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
||||
*/
|
||||
|
||||
namespace Aviat\AnimeClient;
|
||||
|
||||
$whose = $config->get('whose_list') . "'s ";
|
||||
$lastSegment = $urlGenerator->lastSegment();
|
||||
$whose = $_->config->get('whose_list') . "'s ";
|
||||
$lastSegment = $_->lastSegment();
|
||||
$extraSegment = $lastSegment === 'list' ? '/list' : '';
|
||||
$hasAnime = str_contains($GLOBALS['_SERVER']['REQUEST_URI'], 'anime');
|
||||
$hasManga = str_contains($GLOBALS['_SERVER']['REQUEST_URI'], 'manga');
|
||||
@ -12,89 +24,89 @@ $hasManga = str_contains($GLOBALS['_SERVER']['REQUEST_URI'], 'manga');
|
||||
<div id="main-nav" class="flex flex-align-end flex-wrap">
|
||||
<span class="flex-no-wrap grow-1">
|
||||
<?php if( ! str_contains($route_path, 'collection')): ?>
|
||||
<?= $helper->a(
|
||||
$urlGenerator->defaultUrl($url_type),
|
||||
<?= $_->h->a(
|
||||
$_->defaultUrl($url_type),
|
||||
$whose . ucfirst($url_type) . ' List',
|
||||
['aria-current'=> 'page']
|
||||
) ?>
|
||||
<?php if($config->get("show_{$url_type}_collection")): ?>
|
||||
[<?= $helper->a(
|
||||
$url->generate("{$url_type}.collection.view") . $extraSegment,
|
||||
<?php if($_->config->get("show_{$url_type}_collection")): ?>
|
||||
[<?= $_->h->a(
|
||||
$_->urlFromRoute("{$url_type}.collection.view") . $extraSegment,
|
||||
ucfirst($url_type) . ' Collection'
|
||||
) ?>]
|
||||
<?php endif ?>
|
||||
<?php if($config->get("show_{$other_type}_collection")): ?>
|
||||
[<?= $helper->a(
|
||||
$url->generate("{$other_type}.collection.view") . $extraSegment,
|
||||
<?php if($_->config->get("show_{$other_type}_collection")): ?>
|
||||
[<?= $_->h->a(
|
||||
$_->urlFromRoute("{$other_type}.collection.view") . $extraSegment,
|
||||
ucfirst($other_type) . ' Collection'
|
||||
) ?>]
|
||||
<?php endif ?>
|
||||
[<?= $helper->a(
|
||||
$urlGenerator->defaultUrl($other_type) . $extraSegment,
|
||||
[<?= $_->h->a(
|
||||
$_->defaultUrl($other_type) . $extraSegment,
|
||||
ucfirst($other_type) . ' List'
|
||||
) ?>]
|
||||
<?php else: ?>
|
||||
<?= $helper->a(
|
||||
$url->generate("{$url_type}.collection.view") . $extraSegment,
|
||||
<?= $_->h->a(
|
||||
$_->urlFromRoute("{$url_type}.collection.view") . $extraSegment,
|
||||
$whose . ucfirst($url_type) . ' Collection',
|
||||
['aria-current'=> 'page']
|
||||
) ?>
|
||||
<?php if($config->get("show_{$other_type}_collection")): ?>
|
||||
[<?= $helper->a(
|
||||
$url->generate("{$other_type}.collection.view") . $extraSegment,
|
||||
<?php if($_->config->get("show_{$other_type}_collection")): ?>
|
||||
[<?= $_->h->a(
|
||||
$_->urlFromRoute("{$other_type}.collection.view") . $extraSegment,
|
||||
ucfirst($other_type) . ' Collection'
|
||||
) ?>]
|
||||
<?php endif ?>
|
||||
[<?= $helper->a($urlGenerator->defaultUrl('anime') . $extraSegment, 'Anime List') ?>]
|
||||
[<?= $helper->a($urlGenerator->defaultUrl('manga') . $extraSegment, 'Manga List') ?>]
|
||||
[<?= $_->h->a($_->defaultUrl('anime') . $extraSegment, 'Anime List') ?>]
|
||||
[<?= $_->h->a($_->defaultUrl('manga') . $extraSegment, 'Manga List') ?>]
|
||||
<?php endif ?>
|
||||
<?php if ($auth->isAuthenticated() && $config->get(['cache', 'driver']) !== 'null'): ?>
|
||||
<?php if ($_->isAuthenticated() && $_->config->get(['cache', 'driver']) !== 'null'): ?>
|
||||
<span class="flex-no-wrap small-font">
|
||||
<button type="button" class="js-clear-cache user-btn">Clear API Cache</button>
|
||||
</span>
|
||||
<?php endif ?>
|
||||
</span>
|
||||
|
||||
<span class="flex-no-wrap small-font">[<?= $helper->a(
|
||||
$url->generate('default_user_info'),
|
||||
'About '. $config->get('whose_list')
|
||||
<span class="flex-no-wrap small-font">[<?= $_->h->a(
|
||||
$_->urlFromRoute('default_user_info'),
|
||||
'About '. $_->config->get('whose_list')
|
||||
) ?>]</span>
|
||||
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<span class="flex-no-wrap small-font">
|
||||
<?= $helper->a(
|
||||
$url->generate('settings'),
|
||||
<?= $_->h->a(
|
||||
$_->urlFromRoute('settings'),
|
||||
'Settings',
|
||||
['class' => 'bracketed']
|
||||
) ?>
|
||||
</span>
|
||||
<span class="flex-no-wrap small-font">
|
||||
<?= $helper->a(
|
||||
$url->generate('logout'),
|
||||
<?= $_->h->a(
|
||||
$_->urlFromRoute('logout'),
|
||||
'Logout',
|
||||
['class' => 'bracketed']
|
||||
) ?>
|
||||
</span>
|
||||
<?php else: ?>
|
||||
<span class="flex-no-wrap small-font">
|
||||
[<?= $helper->a($url->generate('login'), "{$whose} Login") ?>]
|
||||
[<?= $_->h->a($_->urlFromRoute('login'), "{$whose} Login") ?>]
|
||||
</span>
|
||||
<?php endif ?>
|
||||
</div>
|
||||
<?php if ($container->get('util')->isViewPage() && ($hasAnime || $hasManga)): ?>
|
||||
<?php if ($_->isViewPage() && ($hasAnime || $hasManga)): ?>
|
||||
<nav>
|
||||
<?= $helper->menu($menu_name) ?>
|
||||
<?= $_->h->menu($menu_name) ?>
|
||||
<?php if (stripos($GLOBALS['_SERVER']['REQUEST_URI'], 'history') === FALSE): ?>
|
||||
<br />
|
||||
<ul>
|
||||
<?php $currentView = Util::eq('list', $lastSegment) ? 'list' : 'cover' ?>
|
||||
<li class="<?= Util::isNotSelected('list', $lastSegment) ?>">
|
||||
<a aria-current="<?= Util::ariaCurrent($currentView === 'cover') ?>"
|
||||
href="<?= $urlGenerator->url($route_path) ?>">Cover View</a>
|
||||
href="<?= $_->urlFromPath($route_path) ?>">Cover View</a>
|
||||
</li>
|
||||
<li class="<?= Util::isSelected('list', $lastSegment) ?>">
|
||||
<a aria-current="<?= Util::ariaCurrent($currentView === 'list') ?>"
|
||||
href="<?= $urlGenerator->url("{$route_path}/list") ?>">List View</a>
|
||||
href="<?= $_->urlFromPath("{$route_path}/list") ?>">List View</a>
|
||||
</li>
|
||||
</ul>
|
||||
<?php endif ?>
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<main>
|
||||
<h2>Add Manga to your List</h2>
|
||||
<form action="<?= $action_url ?>" method="post">
|
||||
|
@ -1,6 +1,6 @@
|
||||
<main class="media-list">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate('manga.add.get') ?>">Add Item</a>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute('manga.add.get') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
@ -11,12 +11,12 @@
|
||||
<?php foreach ($sections as $name => $items): ?>
|
||||
<?php if (empty($items)): ?>
|
||||
<section class="status">
|
||||
<h2><?= $escape->html($name) ?></h2>
|
||||
<h2><?= $_->escape->html($name) ?></h2>
|
||||
<h3>There's nothing here!</h3>
|
||||
</section>
|
||||
<?php else: ?>
|
||||
<section class="status">
|
||||
<h2><?= $escape->html($name) ?></h2>
|
||||
<h2><?= $_->escape->html($name) ?></h2>
|
||||
<section class="media-wrap">
|
||||
<?php foreach($items as $item): ?>
|
||||
<?= $component->mangaCover($item, $name) ?>
|
||||
|
@ -1,7 +1,7 @@
|
||||
<main class="details fixed">
|
||||
<section class="flex flex-no-wrap">
|
||||
<aside class="info">
|
||||
<?= $helper->picture("images/manga/{$data['id']}-original.webp", 'jpg', ['class' => 'cover']) ?>
|
||||
<?= $_->h->img($data['cover_image'], ['class' => 'cover', 'width' => '350']) ?>
|
||||
|
||||
<br />
|
||||
|
||||
@ -72,14 +72,14 @@
|
||||
<?php if (count($data['characters']) > 0): ?>
|
||||
<h2>Characters</h2>
|
||||
|
||||
<?= $component->tabs('manga-characters', $data['characters'], static function($list, $role) use ($component, $helper, $url) {
|
||||
<?= $component->tabs('manga-characters', $data['characters'], static function($list, $role) use ($component, $helper, $_) {
|
||||
$rendered = [];
|
||||
foreach ($list as $id => $char)
|
||||
{
|
||||
$rendered[] = $component->character(
|
||||
$char['name'],
|
||||
$url->generate('character', ['slug' => $char['slug']]),
|
||||
$helper->picture("images/characters/{$id}.webp"),
|
||||
$_->urlFromRoute('character', ['slug' => $char['slug']]),
|
||||
$_->h->img($char['image'], ['loading' => 'lazy']),
|
||||
($role !== 'main') ? 'small-character' : 'character'
|
||||
);
|
||||
}
|
||||
@ -95,8 +95,8 @@
|
||||
fn($people) => implode('', array_map(
|
||||
fn ($person) => $component->character(
|
||||
$person['name'],
|
||||
$url->generate('person', ['slug' => $person['slug']]),
|
||||
$helper->picture("images/people/{$person['id']}.webp")
|
||||
$_->urlFromRoute('person', ['slug' => $person['slug']]),
|
||||
$_->h->img($person['image']),
|
||||
),
|
||||
$people
|
||||
))
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<main>
|
||||
<h2>
|
||||
Edit Manga List Item
|
||||
@ -8,9 +8,9 @@
|
||||
<thead>
|
||||
<tr>
|
||||
<th>
|
||||
<h3><?= $escape->html($item['manga']['title']) ?></h3>
|
||||
<h3><?= $_->escape->html($item['manga']['title']) ?></h3>
|
||||
<?php foreach ($item['manga']['titles'] as $title): ?>
|
||||
<h4><?= $escape->html($title) ?></h4>
|
||||
<h4><?= $_->escape->html($title) ?></h4>
|
||||
<?php endforeach ?>
|
||||
</th>
|
||||
</tr>
|
||||
@ -18,7 +18,7 @@
|
||||
<tbody>
|
||||
<tr>
|
||||
<td rowspan="9">
|
||||
<?= $helper->picture("images/manga/{$item['manga']['id']}-original.webp", "jpg", [], ["width" => "390"]) ?>
|
||||
<?= $_->h->img($item['manga']['image']) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -46,13 +46,6 @@
|
||||
value="<?= $item['chapters']['read'] ?>"/> / <?= $item['chapters']['total'] ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="volumes_read">Volumes Read</label></td>
|
||||
<td>
|
||||
<?php /*<input type="number" disabled="disabled" min="0" name="volumes_read" id="volumes_read" value="" /> */ ?>
|
||||
- / <?= $item['volumes']['total'] ?>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><label for="rereading_flag">Rereading?</label></td>
|
||||
<td>
|
||||
@ -71,7 +64,7 @@
|
||||
<tr>
|
||||
<td><label for="notes">Notes</label></td>
|
||||
<td>
|
||||
<textarea name="notes" id="notes"><?= $escape->html($item['notes']) ?></textarea>
|
||||
<textarea name="notes" id="notes"><?= $_->escape->html($item['notes']) ?></textarea>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
@ -90,7 +83,7 @@
|
||||
</form>
|
||||
<fieldset>
|
||||
<legend>Danger Zone</legend>
|
||||
<form class="js-delete" action="<?= $url->generate('manga.delete') ?>" method="post">
|
||||
<form class="js-delete" action="<?= $_->urlFromRoute('manga.delete') ?>" method="post">
|
||||
<table class="form invisible">
|
||||
<tbody>
|
||||
<tr>
|
||||
|
@ -1,6 +1,6 @@
|
||||
<main class="media-list">
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $url->generate('manga.add.get') ?>">Add Item</a>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute('manga.add.get') ?>">Add Item</a>
|
||||
<?php endif ?>
|
||||
<?php if (empty($sections)): ?>
|
||||
<h3>There's nothing here!</h3>
|
||||
@ -16,13 +16,12 @@
|
||||
<table class='media-wrap'>
|
||||
<thead>
|
||||
<tr>
|
||||
<?php if ($auth->isAuthenticated()): ?>
|
||||
<?php if ($_->isAuthenticated()): ?>
|
||||
<td> </td>
|
||||
<?php endif ?>
|
||||
<th>Title</th>
|
||||
<th>Rating</th>
|
||||
<th>Completed Chapters</th>
|
||||
<th># of Volumes</th>
|
||||
<th class='numeric'>Score</th>
|
||||
<th class='numeric'>Completed Chapters</th>
|
||||
<th>Attributes</th>
|
||||
<th>Type</th>
|
||||
</tr>
|
||||
@ -30,9 +29,9 @@
|
||||
<tbody>
|
||||
<?php foreach($items as $item): ?>
|
||||
<tr id="manga-<?= $item['id'] ?>">
|
||||
<?php if($auth->isAuthenticated()): ?>
|
||||
<?php if($_->isAuthenticated()): ?>
|
||||
<td>
|
||||
<a class="bracketed" href="<?= $url->generate('edit', [
|
||||
<a class="bracketed" href="<?= $_->urlFromRoute('edit', [
|
||||
'controller' => 'manga',
|
||||
'id' => $item['id'],
|
||||
'status' => $name
|
||||
@ -40,7 +39,7 @@
|
||||
</td>
|
||||
<?php endif ?>
|
||||
<td class="align-left">
|
||||
<a href="<?= $url->generate('manga.details', ['id' => $item['manga']['slug']]) ?>">
|
||||
<a href="<?= $_->urlFromRoute('manga.details', ['id' => $item['manga']['slug']]) ?>">
|
||||
<?= $item['manga']['title'] ?>
|
||||
</a>
|
||||
<?php foreach($item['manga']['titles'] as $title): ?>
|
||||
@ -49,7 +48,6 @@
|
||||
</td>
|
||||
<td><?= $item['user_rating'] ?> / 10</td>
|
||||
<td><?= $item['chapters']['read'] ?> / <?= $item['chapters']['total'] ?></td>
|
||||
<td><?= $item['volumes']['total'] ?></td>
|
||||
<td>
|
||||
<ul>
|
||||
<?php if ($item['reread'] == 1): ?>
|
||||
@ -77,4 +75,4 @@
|
||||
<?php endforeach ?>
|
||||
<?php endif ?>
|
||||
</main>
|
||||
<script defer="defer" src="<?= $urlGenerator->assetUrl('js/tables.min.js') ?>"></script>
|
||||
<script defer="defer" src="<?= $_->assetUrl('js/tables.min.js') ?>"></script>
|
||||
|
@ -1,5 +1,5 @@
|
||||
<div class="message <?= $escape->attr($message_type) ?>">
|
||||
<div class="message <?= $_->escape->attr($message_type) ?>">
|
||||
<span class="icon"></span>
|
||||
<?= $escape->html($message) ?>
|
||||
<?= $_->escape->html($message) ?>
|
||||
<span class="close"></span>
|
||||
</div>
|
@ -1,16 +1,16 @@
|
||||
<?php
|
||||
use function Aviat\AnimeClient\getLocalImg;
|
||||
?>
|
||||
<main class="details fixed">
|
||||
<section class="flex flex-no-wrap">
|
||||
<div>
|
||||
<?= $helper->picture("images/people/{$data['id']}-original.webp", 'jpg', ['class' => 'cover' ]) ?>
|
||||
<?= $_->h->img($data['image'], ['class' => 'cover' ]) ?>
|
||||
</div>
|
||||
<div>
|
||||
<h2 class="toph"><?= $data['name'] ?></h2>
|
||||
<?php foreach ($data['names'] as $name): ?>
|
||||
<h3><?= $name ?></h3>
|
||||
<?php endforeach ?>
|
||||
<?php if ( ! empty($data['birthday'])): ?>
|
||||
<h4><?= $data['birthday'] ?></h4>
|
||||
<?php endif ?>
|
||||
<br />
|
||||
<hr />
|
||||
<div class="description">
|
||||
@ -37,10 +37,10 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<section class="content media-wrap flex flex-wrap flex-justify-start">
|
||||
<?php foreach ($casting as $sid => $series): ?>
|
||||
<?php $mediaType = in_array($type, ['anime', 'manga'], TRUE) ? $type : 'anime'; ?>
|
||||
<?= $component->media(
|
||||
<?= $_->component->media(
|
||||
$series['titles'],
|
||||
$url->generate("{$mediaType}.details", ['id' => $series['slug']]),
|
||||
$helper->picture("images/{$type}/{$sid}.webp")
|
||||
$_->urlFromRoute("{$mediaType}.details", ['id' => $series['slug']]),
|
||||
$_->h->img($series['image'], ['width' => 220, 'loading' => 'lazy'])
|
||||
) ?>
|
||||
<?php endforeach; ?>
|
||||
</section>
|
||||
@ -55,21 +55,21 @@ use function Aviat\AnimeClient\getLocalImg;
|
||||
<?php if ( ! empty($data['characters'])): ?>
|
||||
<section>
|
||||
<h3>Voice Acting Roles</h3>
|
||||
<?= $component->tabs('voice-acting-roles', $data['characters'], static function ($characterList) use ($component, $helper, $url) {
|
||||
<?= $component->tabs('voice-acting-roles', $data['characters'], static function ($characterList) use ($component, $helper, $_) {
|
||||
$voiceRoles = [];
|
||||
foreach ($characterList as $cid => $item):
|
||||
$character = $component->character(
|
||||
$item['character']['canonicalName'],
|
||||
$url->generate('character', ['slug' => $item['character']['slug']]),
|
||||
$helper->picture(getLocalImg($item['character']['image']['original'] ?? null))
|
||||
$_->urlFromRoute('character', ['slug' => $item['character']['slug']]),
|
||||
$_->h->img($item['character']['image'], ['loading' => 'lazy']),
|
||||
);
|
||||
$medias = [];
|
||||
foreach ($item['media'] as $sid => $series)
|
||||
{
|
||||
$medias[] = $component->media(
|
||||
$series['titles'],
|
||||
$url->generate('anime.details', ['id' => $series['slug']]),
|
||||
$helper->picture("images/anime/{$sid}.webp")
|
||||
$_->urlFromRoute('anime.details', ['id' => $series['slug']]),
|
||||
$_->h->img($series['image'], ['width' => 220, 'loading' => 'lazy'])
|
||||
);
|
||||
}
|
||||
$media = implode('', array_map('mb_trim', $medias));
|
||||
|
24
app/views/settings/_anilist.php
Normal file
24
app/views/settings/_anilist.php
Normal file
@ -0,0 +1,24 @@
|
||||
<?php if ( ! $hasRequiredAnilistConfig): ?>
|
||||
<p class="static-message info">See the <a href="https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient/wiki/anilist">wiki</a> to learn how to set up Anilist integration. </p>
|
||||
<?php else: ?>
|
||||
<?php $auth = $anilistModel->checkAuth(); ?>
|
||||
<?php if (array_key_exists('errors', $auth)): ?>
|
||||
<p class="static-message error">Anilist API Client is Not Authorized.</p>
|
||||
<?= $_->h->a(
|
||||
$_->urlFromRoute('anilist-redirect'),
|
||||
'Link Anilist Account',
|
||||
['class' => 'bracketed user-btn']
|
||||
) ?>
|
||||
<?php else: ?>
|
||||
<?php $expires = $_->config->get(['anilist', 'access_token_expires']); ?>
|
||||
<p class="static-message info">
|
||||
Linked to Anilist. Your access token will expire around <?= date('F j, Y, g:i a T', $expires) ?>
|
||||
</p>
|
||||
<?php require __DIR__ . '/_form.php' ?>
|
||||
<?= $_->h->a(
|
||||
$_->urlFromRoute('anilist-redirect'),
|
||||
'Update Access Token',
|
||||
['class' => 'bracketed user-btn']
|
||||
) ?>
|
||||
<?php endif ?>
|
||||
<?php endif ?>
|
@ -1,5 +1,5 @@
|
||||
<article>
|
||||
<label for="<?= $fieldName ?>"><?= $field['title'] ?></label><br />
|
||||
<small><?= $field['description'] ?></small><br />
|
||||
<?= $helper->field($fieldName, $field); ?>
|
||||
<?= $_->h->field($fieldName, $field); ?>
|
||||
</article>
|
@ -19,6 +19,6 @@
|
||||
<?php elseif ( ! empty($field['display'])): ?>
|
||||
<?php include '_field.php' ?>
|
||||
<?php else: ?>
|
||||
<?php $hiddenFields[] = $helper->field($fieldName, $field); ?>
|
||||
<?php $hiddenFields[] = $_->h->field($fieldName, $field); ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
||||
|
@ -15,6 +15,6 @@
|
||||
<?php if ( ! empty($field['display'])): ?>
|
||||
<?php include '_field.php' ?>
|
||||
<?php else: ?>
|
||||
<?php $hiddenFields[] = $helper->field($fieldName, $field); ?>
|
||||
<?php $hiddenFields[] = $_->h->field($fieldName, $field); ?>
|
||||
<?php endif ?>
|
||||
<?php endforeach ?>
|
@ -1,5 +1,5 @@
|
||||
<?php
|
||||
if ( ! $auth->isAuthenticated())
|
||||
if ( ! $_->isAuthenticated())
|
||||
{
|
||||
echo '<h1>Not Authorized</h1>';
|
||||
return;
|
||||
@ -16,7 +16,7 @@ $hiddenFields = [];
|
||||
$nestedPrefix = 'config';
|
||||
?>
|
||||
|
||||
<form action="<?= $url->generate('settings-post') ?>" method="POST">
|
||||
<form action="<?= $_->urlFromRoute('settings-post') ?>" method="POST">
|
||||
<main class='settings form'>
|
||||
<button type="submit">Save Changes</button>
|
||||
<div class="tabs">
|
||||
@ -28,29 +28,11 @@ $nestedPrefix = 'config';
|
||||
/>
|
||||
<label for="settings-tab<?= $i ?>"><h3><?= $sectionMapping[$section] ?></h3></label>
|
||||
<section class="content">
|
||||
<?php if ($section === 'anilist'): ?>
|
||||
<?php $auth = $anilistModel->checkAuth(); ?>
|
||||
<?php if (array_key_exists('errors', $auth)): ?>
|
||||
<p class="static-message error">Not Authorized.</p>
|
||||
<?= $helper->a(
|
||||
$url->generate('anilist-redirect'),
|
||||
'Link Anilist Account'
|
||||
) ?>
|
||||
<?php else: ?>
|
||||
<?php $expires = $config->get(['anilist', 'access_token_expires']); ?>
|
||||
<p class="static-message info">
|
||||
Linked to Anilist. Your access token will expire around <?= date('F j, Y, g:i a T', $expires) ?>
|
||||
</p>
|
||||
<?php require __DIR__ . '/_form.php' ?>
|
||||
<?= $helper->a(
|
||||
$url->generate('anilist-redirect'),
|
||||
'Update Access Token',
|
||||
['class' => 'bracketed user-btn']
|
||||
) ?>
|
||||
<?php endif ?>
|
||||
<?php else: ?>
|
||||
<?php require __DIR__ . '/_form.php' ?>
|
||||
<?php endif ?>
|
||||
<?php
|
||||
($section === 'anilist')
|
||||
? require __DIR__ . '/_anilist.php'
|
||||
: require __DIR__ . '/_form.php'
|
||||
?>
|
||||
</section>
|
||||
<?php $i++; ?>
|
||||
<?php endforeach ?>
|
||||
@ -62,7 +44,3 @@ $nestedPrefix = 'config';
|
||||
<button type="submit">Save Changes</button>
|
||||
</main>
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
use function Aviat\AnimeClient\checkFolderPermissions;
|
||||
|
||||
$setupErrors = checkFolderPermissions($container->get('config'));
|
||||
$setupErrors = checkFolderPermissions($_->config);
|
||||
?>
|
||||
|
||||
<?php if ( ! empty($setupErrors)): ?>
|
||||
|
@ -3,7 +3,8 @@ use Aviat\AnimeClient\Kitsu;
|
||||
?>
|
||||
<main class="user-page details">
|
||||
<h2 class="toph">
|
||||
<?= $helper->a(
|
||||
About
|
||||
<?= $_->h->a(
|
||||
"https://kitsu.io/users/{$data['slug']}",
|
||||
$data['name'], [
|
||||
'title' => 'View profile on Kitsu'
|
||||
@ -11,32 +12,49 @@ use Aviat\AnimeClient\Kitsu;
|
||||
?>
|
||||
</h2>
|
||||
|
||||
<p><?= $escape->html($data['about']) ?></p>
|
||||
|
||||
<section class="flex flex-no-wrap">
|
||||
<aside class="info">
|
||||
<center>
|
||||
<?= $helper->img($urlGenerator->assetUrl($data['avatar']), ['alt' => '']); ?>
|
||||
</center>
|
||||
<table class="media-details invisible">
|
||||
<tr>
|
||||
<?php if($data['avatar'] !== null): ?>
|
||||
<td><?= $_->h->img($data['avatar'], ['alt' => '', 'width' => '225']); ?></td>
|
||||
<?php endif ?>
|
||||
<td><?= $_->escape->html($data['about']) ?></td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<table class="media-details">
|
||||
<?php foreach ([
|
||||
'joinDate' => 'Joined',
|
||||
'birthday' => 'Birthday',
|
||||
'gender' => 'Gender',
|
||||
'location' => 'Location'
|
||||
] as $key => $label): ?>
|
||||
<?php if ($data[$key] !== null): ?>
|
||||
<tr>
|
||||
<td>Location</td>
|
||||
<td><?= $data['location'] ?></td>
|
||||
<td><?= $label ?></td>
|
||||
<td><?= $data[$key] ?></td>
|
||||
</tr>
|
||||
<?php endif ?>
|
||||
<?php endforeach; ?>
|
||||
|
||||
<?php if ($data['website'] !== null): ?>
|
||||
<tr>
|
||||
<td>Website</td>
|
||||
<td><?= $helper->a($data['website'], $data['website']) ?></td>
|
||||
<td><?= $_->h->a($data['website'], $data['website']) ?></td>
|
||||
</tr>
|
||||
<?php if ( ! empty($data['waifu'])): ?>
|
||||
<?php endif ?>
|
||||
|
||||
<?php if ($data['waifu']['character'] !== null): ?>
|
||||
<tr>
|
||||
<td><?= $escape->html($data['waifu']['label']) ?></td>
|
||||
<td><?= $_->escape->html($data['waifu']['label']) ?></td>
|
||||
<td>
|
||||
<?php
|
||||
$character = $data['waifu']['character'];
|
||||
echo $helper->a(
|
||||
$url->generate('character', ['slug' => $character['slug']]),
|
||||
$character['names']['canonical']
|
||||
echo $_->component->character(
|
||||
$character['names']['canonical'],
|
||||
$_->urlFromRoute('character', ['slug' => $character['slug']]),
|
||||
$_->h->img(Kitsu::getImage($character))
|
||||
);
|
||||
?>
|
||||
</td>
|
||||
@ -57,8 +75,7 @@ use Aviat\AnimeClient\Kitsu;
|
||||
<article>
|
||||
<?php if ( ! empty($data['favorites'])): ?>
|
||||
<h3>Favorites</h3>
|
||||
<?= $component->tabs('user-favorites', $data['favorites'], static function ($items, $type) use ($component, $helper, $url) {
|
||||
$rendered = [];
|
||||
<?= $_->component->tabs('user-favorites', $data['favorites'], static function ($items, $type) use ($_) {
|
||||
if ($type === 'character')
|
||||
{
|
||||
uasort($items, fn ($a, $b) => $a['names']['canonical'] <=> $b['names']['canonical']);
|
||||
@ -68,28 +85,21 @@ use Aviat\AnimeClient\Kitsu;
|
||||
uasort($items, fn ($a, $b) => $a['titles']['canonical'] <=> $b['titles']['canonical']);
|
||||
}
|
||||
|
||||
foreach ($items as $id => $item)
|
||||
{
|
||||
if ($type === 'character')
|
||||
{
|
||||
$rendered[] = $component->character(
|
||||
$rendered = array_map(fn ($item) => match ($type) {
|
||||
'character' => $_->component->character(
|
||||
$item['names']['canonical'],
|
||||
$url->generate('character', ['slug' => $item['slug']]),
|
||||
$helper->picture("images/characters/{$item['id']}.webp")
|
||||
);
|
||||
}
|
||||
else
|
||||
{
|
||||
$rendered[] = $component->media(
|
||||
$_->urlFromRoute('character', ['slug' => $item['slug']]),
|
||||
$_->h->img(Kitsu::getImage($item))
|
||||
),
|
||||
default => $_->component->media(
|
||||
array_merge(
|
||||
[$item['titles']['canonical']],
|
||||
Kitsu::getFilteredTitles($item['titles']),
|
||||
),
|
||||
$url->generate("{$type}.details", ['id' => $item['slug']]),
|
||||
$helper->picture("images/{$type}/{$item['id']}.webp"),
|
||||
);
|
||||
}
|
||||
}
|
||||
$_->urlFromRoute("{$type}.details", ['id' => $item['slug']]),
|
||||
$_->h->img(Kitsu::getPosterImage($item), ['width' => 220]),
|
||||
),
|
||||
}, $items);
|
||||
|
||||
return implode('', array_map('mb_trim', $rendered));
|
||||
|
||||
|
@ -1,28 +0,0 @@
|
||||
<documentation title="Closing comments instead of PHP closing tag">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
The PHP closing tag on a PHP document ?> is optional to the PHP parser. However, if used, any whitespace following the closing tag, whether introduced by the developer, user, or an FTP application, can cause unwanted output, PHP errors, or if the latter are suppressed, blank pages. For this reason, all PHP files should OMIT the closing PHP tag, and instead use a comment block to mark the end of file and it's location relative to the application root. This allows you to still identify a file as being complete and not truncated.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of valid closing comments">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
echo "Here's my code!";
|
||||
|
||||
/* End of file myfile.php */
|
||||
/* Location: ./system/modules/mymodule/myfile.php */
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of invalid closing comments">
|
||||
<![CDATA[
|
||||
<?php
|
||||
|
||||
echo "Here's my code!";
|
||||
|
||||
?>
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,7 +0,0 @@
|
||||
<documentation title="Unicode (UTF-8) encoding without BOM">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Files should be saved with Unicode (UTF-8) encoding. The BOM should not be used. Unlike UTF-16 and UTF-32, there's no byte order to indicate in a UTF-8 encoded file, and the BOM can have a negative side effect in PHP of sending output, preventing the application from being able to set its own headers. Unix line endings should be used (LF).
|
||||
]]>
|
||||
</standard>
|
||||
</documentation>
|
@ -1,31 +0,0 @@
|
||||
<documentation title="Constructor Names">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of valid constructor name">
|
||||
<![CDATA[
|
||||
class Super_class
|
||||
{
|
||||
function Super_class()
|
||||
{
|
||||
echo 'Some code here !';
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of invalid constructor name">
|
||||
<![CDATA[
|
||||
class Super_class
|
||||
{
|
||||
function __constructor()
|
||||
{
|
||||
echo 'Some code here !';
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,21 +0,0 @@
|
||||
<documentation title="Class names">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of valid class names">
|
||||
<![CDATA[
|
||||
class Super_class
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of invalid class names">
|
||||
<![CDATA[
|
||||
class SuperClass // words not separated with underscores and words next to the first one start with an upper case
|
||||
class superclass // words not separated with underscores
|
||||
class Super_Class // words next to the first one start with an upper case
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,21 +0,0 @@
|
||||
<documentation title="File names">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
To be able to find which class is contained in a file, file names should be case-insensitively equal to class names. Some operating systems and tools are case-insensitive, though other are. So, file names should be in lower case to avoid any trouble.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of valid file names">
|
||||
<![CDATA[
|
||||
super_class.php
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of invalid file names">
|
||||
<![CDATA[
|
||||
superclass.php // words not separated with underscores
|
||||
SuperClass.php // not in lower case and words not separated with underscores
|
||||
Super_class.php // not in lower case
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,27 +0,0 @@
|
||||
<documentation title="Function and Method Names">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Class names should always start with an uppercase letter. Multiple words should be separated with an underscore, and not CamelCased. All other class methods should be entirely lowercased and named to clearly indicate their function, preferably including a verb. Try to avoid overly long and verbose names.
|
||||
Methods and variables that are only accessed internally by your class, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of valid method names">
|
||||
<![CDATA[
|
||||
function get_file_properties() // descriptive, underscore separator, and all lowercase letters
|
||||
private function _get_file_properties()
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of invalid method names">
|
||||
<![CDATA[
|
||||
function fileproperties() // not descriptive and needs underscore separator
|
||||
function fileProperties() // not descriptive and uses CamelCase
|
||||
function getfileproperties() // Better! But still missing underscore separator
|
||||
function getFileProperties() // uses CamelCase
|
||||
function get_the_file_properties_from_the_file() // wordy
|
||||
private function get_the_file_properties() // not prefixed with an underscor, though private
|
||||
function _get_the_file_properties() // prefixed with an underscor, though public
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,31 +0,0 @@
|
||||
<documentation title="Variable names">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Namely, variables should contain only lowercase letters, use underscore separators, and be reasonably named to indicate their purpose and contents. Very short, non-word variables should only be used as iterators in for() loops.
|
||||
Methods and variables that are only accessed internally by your class, such as utility and helper functions that your public methods use for code abstraction, should be prefixed with an underscore.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of valid variable names">
|
||||
<![CDATA[
|
||||
for ($j = 0; $j < 10; $j++)
|
||||
$str
|
||||
$buffer
|
||||
$group_id
|
||||
$last_city
|
||||
private $_internal_data;
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of invalid variable names">
|
||||
<![CDATA[
|
||||
$j = 'foo'; // single letter variables should only be used in for() loops
|
||||
$Str // contains uppercase letters
|
||||
$bufferedText // uses CamelCasing, and could be shortened without losing semantic meaning
|
||||
$groupid // multiple words, needs underscore separator
|
||||
$name_of_last_city_used // too long
|
||||
private $internal_data; // not prefixed with an underscor, though private
|
||||
$_public_attribute; // prefixed with an underscor, though public
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,40 +0,0 @@
|
||||
<documentation title="Strict comparison operators">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Some PHP functions return FALSE on failure, but may also have a valid return value of "" or 0, which would evaluate to FALSE in loose comparisons. Be explicit by comparing the variable type when using these return values in conditionals to ensure the return value is indeed what you expect, and not a value that has an equivalent loose-type evaluation.
|
||||
Use the same stringency in returning and checking your own variables. Use === and !== as necessary.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Valid strict comparison">
|
||||
<![CDATA[
|
||||
if (strpos($str, 'foo') === FALSE) {
|
||||
echo 'Do something.';
|
||||
}
|
||||
|
||||
function build_string($str = "")
|
||||
{
|
||||
if ($str === "") {
|
||||
echo 'Buid string.';
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code>
|
||||
<code title="Invalid loose comparison">
|
||||
<![CDATA[
|
||||
// If 'foo' is at the beginning of the string, strpos will return a 0,
|
||||
// resulting in this conditional evaluating as TRUE
|
||||
if (strpos($str, 'foo') == FALSE) {
|
||||
echo 'Do something.';
|
||||
}
|
||||
|
||||
function build_string($str = "")
|
||||
{
|
||||
if ($str == "") { // uh-oh! What if FALSE or the integer 0 is passed as an argument?
|
||||
echo 'Buid string.';
|
||||
}
|
||||
}
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,28 +0,0 @@
|
||||
<documentation title="Double-quoted strings">
|
||||
<standard>
|
||||
<![CDATA[
|
||||
Always use single quoted strings unless you need variables parsed, and in cases where you do need variables parsed, use braces to prevent greedy token parsing. You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.
|
||||
]]>
|
||||
</standard>
|
||||
<code_comparison>
|
||||
<code title="Examples of invalid double-quoted strings">
|
||||
<![CDATA[
|
||||
"My String" // no variable parsing, so no use for double quotes
|
||||
"My string $foo" // needs braces
|
||||
'SELECT foo FROM bar WHERE baz = \'bag\'' // ugly
|
||||
'\r\n' // it isn't wrong, but it won't be interpreted as a new line feed
|
||||
]]>
|
||||
</code>
|
||||
<code title="Examples of valid double-quoted strings">
|
||||
<![CDATA[
|
||||
'My String'
|
||||
"My string {$foo}" // variables in strings may be enclosed with braces in 2 ways
|
||||
"My string ${foo}"
|
||||
"My string {$foo['bar']}" // variables in strings may be an array entry
|
||||
"My string {$foo->bar}" // variables in strings may be an object attribute
|
||||
"SELECT foo FROM bar WHERE baz = 'bag'"
|
||||
"\n" // not specified in Code Igniter coding standard, but it should be allowed
|
||||
]]>
|
||||
</code>
|
||||
</code_comparison>
|
||||
</documentation>
|
@ -1,187 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Commenting_InlineCommentSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Commenting_InlineCommentSniff.
|
||||
*
|
||||
* Ensure the use of single line comments within code (i.e //)
|
||||
* and blank lines between large comment blocks and code.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
namespace CodeIgniter\Sniffs\Commenting;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class InlineCommentSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* @var int Limit defining long comments.
|
||||
* Long comments count $longCommentLimit or more lines.
|
||||
*/
|
||||
public $longCommentLimit = 5;
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_COMMENT
|
||||
);
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// keep testing only if it's about the first comment of the block
|
||||
$previousCommentPtr = $phpcsFile->findPrevious($tokens[$stackPtr]['code'], $stackPtr - 1);
|
||||
if ($tokens[$previousCommentPtr]['line'] !== $tokens[$stackPtr]['line'] - 1) {
|
||||
if (TRUE !== $this->_checkCommentStyle($phpcsFile, $stackPtr)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$commentLines = $this->_getCommentBlock($phpcsFile, $stackPtr);
|
||||
|
||||
if (count($commentLines) >= $this->longCommentLimit) {
|
||||
$this->_checkBlankLinesAroundLongComment($phpcsFile, $commentLines);
|
||||
}
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Add error to $phpcsFile, if comment pointed by $stackPtr doesn't start
|
||||
* with '//'.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* that has to be a comment.
|
||||
*
|
||||
* @return bool TRUE if the content of the token pointed by $stackPtr starts
|
||||
* with //, FALSE if an error was added to $phpcsFile.
|
||||
*/
|
||||
private function _checkCommentStyle(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
if ($tokens[$stackPtr]['content'][0] === '#') {
|
||||
$error = 'Perl-style comments are not allowed; use "// Comment" or DocBlock comments instead';
|
||||
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
|
||||
return FALSE;
|
||||
} else if (substr($tokens[$stackPtr]['content'], 0, 2) === '/*'
|
||||
|| $tokens[$stackPtr]['content'][0] === '*'
|
||||
) {
|
||||
$error = 'Multi lines comments are not allowed; use "// Comment" DocBlock comments instead';
|
||||
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
|
||||
return FALSE;
|
||||
} else if (substr($tokens[$stackPtr]['content'], 0, 2) !== '//') {
|
||||
$error = 'Use single line or DocBlock comments within code';
|
||||
$phpcsFile->addError($error, $stackPtr, 'WrongStyle');
|
||||
return FALSE;
|
||||
}
|
||||
return TRUE;
|
||||
}//_checkCommentStyle()
|
||||
|
||||
|
||||
/**
|
||||
* Gather into an array all comment lines to which $stackPtr belongs.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr Pointer to the first comment line.
|
||||
*
|
||||
* @return type array Pointers to tokens making up the comment block.
|
||||
*/
|
||||
private function _getCommentBlock(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$commentLines = array($stackPtr);
|
||||
$nextComment = $stackPtr;
|
||||
$lastLine = $tokens[$stackPtr]['line'];
|
||||
|
||||
while (($nextComment = $phpcsFile->findNext($tokens[$stackPtr]['code'], ($nextComment + 1), null, false)) !== false) {
|
||||
if (($tokens[$nextComment]['line'] - 1) !== $lastLine) {
|
||||
// Not part of the block.
|
||||
break;
|
||||
}
|
||||
|
||||
$lastLine = $tokens[$nextComment]['line'];
|
||||
$commentLines[] = $nextComment;
|
||||
}
|
||||
|
||||
return $commentLines;
|
||||
}//_getCommentBlock()
|
||||
|
||||
|
||||
/**
|
||||
* Add errors to $phpcsFile, if $commentLines isn't enclosed with blank lines.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param array $commentLines Lines of the comment block being checked.
|
||||
*
|
||||
* @return bool TRUE if $commentLines is enclosed with at least a blank line
|
||||
* before and after, FALSE otherwise.
|
||||
*/
|
||||
private function _checkBlankLinesAroundLongComment(File $phpcsFile, array $commentLines)
|
||||
{
|
||||
$hasBlankLinesAround = TRUE;
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// check blank line before the long comment
|
||||
$firstCommentPtr = reset($commentLines);
|
||||
$firstPreviousSpacePtr = $firstCommentPtr - 1;
|
||||
while (T_WHITESPACE === $tokens[$firstPreviousSpacePtr]['code'] && $firstPreviousSpacePtr > 0) {
|
||||
$firstPreviousSpacePtr--;
|
||||
}
|
||||
if ($tokens[$firstPreviousSpacePtr]['line'] >= $tokens[$firstCommentPtr]['line'] - 1) {
|
||||
$error = "Please add a blank line before comments counting more than {$this->longCommentLimit} lines.";
|
||||
$phpcsFile->addError($error, $firstCommentPtr, 'LongCommentWithoutSpacing');
|
||||
$hasBlankLinesAround = FALSE;
|
||||
}
|
||||
|
||||
// check blank line after the long comment
|
||||
$lastCommentPtr = end($commentLines);
|
||||
$lastNextSpacePtr = $lastCommentPtr + 1;
|
||||
while (T_WHITESPACE === $tokens[$lastNextSpacePtr]['code'] && $lastNextSpacePtr < count($tokens)) {
|
||||
$lastNextSpacePtr++;
|
||||
}
|
||||
if ($tokens[$lastNextSpacePtr]['line'] <= $tokens[$lastCommentPtr]['line'] + 1) {
|
||||
$error = "Please add a blank line after comments counting more than {$this->longCommentLimit} lines.";
|
||||
$phpcsFile->addError($error, $lastCommentPtr, 'LongCommentWithoutSpacing');
|
||||
$hasBlankLinesAround = FALSE;
|
||||
}
|
||||
|
||||
return $hasBlankLinesAround;
|
||||
}//end _checkBlanksAroundLongComment()
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,98 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_ByteOrderMarkSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_ByteOrderMarkSniff.
|
||||
*
|
||||
* Ensures that no BOM appears at the beginning of file.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Files;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ByteOrderMarkSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array( T_OPEN_TAG );
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* List of supported BOM definitions.
|
||||
*
|
||||
* Use encoding names as keys and hex BOM representations as values.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getBomDefinitions()
|
||||
{
|
||||
return array(
|
||||
'UTF-8' => 'efbbbf',
|
||||
'UTF-16 (BE)' => 'feff',
|
||||
'UTF-16 (LE)' => 'fffe',
|
||||
'UTF-32 (BE)' => '0000feff',
|
||||
'UTF-32 (LE)' => 'fffe0000'
|
||||
);
|
||||
}//end getBomDefinitions()
|
||||
|
||||
/**
|
||||
* Process tokens.
|
||||
*
|
||||
* Actually, only proceed when we're at index 0, this should be the only case
|
||||
* that will contain BOM. Then check if BOM definition matches what
|
||||
* we've found as file's inline HTML. Inline HTML could be longer than just BOM
|
||||
* so make sure you test as much as needed.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr )
|
||||
{
|
||||
// We are only interested if this is the first open tag.
|
||||
if ($stackPtr !== 0) {
|
||||
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$fileStartString = $tokens[0]['content'];
|
||||
foreach ($this->getBomDefinitions() as $bomName => $expectedBomHex) {
|
||||
$bomByteLength = strlen($expectedBomHex) / 2;
|
||||
$fileStartHex = bin2hex(substr($fileStartString, 0, $bomByteLength));
|
||||
if ($fileStartHex === $expectedBomHex) {
|
||||
$error = "File contains a $bomName byte order mark (BOM).";
|
||||
$phpcsFile->addError($error, $stackPtr, 123);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}//end process()
|
||||
}
|
@ -1,222 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_Utf8EncodingSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_Utf8EncodingSniff.
|
||||
*
|
||||
* Ensures that PHP files are encoded with Unicode (UTF-8) encoding.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Files;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class Utf8EncodingSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_OPEN_TAG
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We are only interested if this is the first open tag.
|
||||
if ($stackPtr !== 0) {
|
||||
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$file_path = $phpcsFile->getFilename();
|
||||
$file_name = basename($file_path);
|
||||
$file_content = file_get_contents($file_path);
|
||||
if (false === mb_check_encoding($file_content, 'UTF-8')) {
|
||||
$error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding.';
|
||||
$phpcsFile->addError($error, 0);
|
||||
}
|
||||
if ( ! self::_checkUtf8W3c($file_content)) {
|
||||
$error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not successfully pass the W3C test.';
|
||||
$phpcsFile->addError($error, 0);
|
||||
}
|
||||
if ( ! self::_checkUtf8Rfc3629($file_content)) {
|
||||
$error = 'File "' . $file_name . '" should be saved with Unicode (UTF-8) encoding, but it did not meet RFC3629 requirements.';
|
||||
$phpcsFile->addError($error, 0);
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Checks that the string $content contains only valid UTF-8 chars
|
||||
* using W3C's method.
|
||||
* Returns true if $content contains only UTF-8 chars, false otherwise.
|
||||
*
|
||||
* @param string $content String to check.
|
||||
*
|
||||
* @return bool true if $content contains only UTF-8 chars, false otherwise.
|
||||
*
|
||||
* @see http://w3.org/International/questions/qa-forms-utf-8.html
|
||||
*/
|
||||
private static function _checkUtf8W3c($content)
|
||||
{
|
||||
$content_chunks=self::mb_chunk_split($content, 4096, '');
|
||||
foreach($content_chunks as $content_chunk)
|
||||
{
|
||||
$preg_result= preg_match(
|
||||
'%^(?:
|
||||
[\x09\x0A\x0D\x20-\x7E] # ASCII
|
||||
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
|
||||
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs
|
||||
| [\xE1-\xEC\xEE\xEF][\x80-\xBF]{2} # straight 3-byte
|
||||
| \xED[\x80-\x9F][\x80-\xBF] # excluding surrogates
|
||||
| \xF0[\x90-\xBF][\x80-\xBF]{2} # planes 1-3
|
||||
| [\xF1-\xF3][\x80-\xBF]{3} # planes 4-15
|
||||
| \xF4[\x80-\x8F][\x80-\xBF]{2} # plane 16
|
||||
)*$%xs',
|
||||
$content_chunk
|
||||
);
|
||||
if($preg_result!==1)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
return true;
|
||||
}//end _checkUtf8W3c()
|
||||
|
||||
/**
|
||||
* Checks that the string $content contains only valid UTF-8 chars
|
||||
* using the method described in RFC 3629.
|
||||
* Returns true if $content contains only UTF-8 chars, false otherwise.
|
||||
*
|
||||
* @param string $content String to check.
|
||||
*
|
||||
* @return bool true if $content contains only UTF-8 chars, false otherwise.
|
||||
*
|
||||
* @see http://www.php.net/manual/en/function.mb-detect-encoding.php#85294
|
||||
*/
|
||||
private static function _checkUtf8Rfc3629($content)
|
||||
{
|
||||
$len = strlen($content);
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$c = ord($content[$i]);
|
||||
if ($c > 128) {
|
||||
if (($c >= 254)) {
|
||||
return false;
|
||||
} elseif ($c >= 252) {
|
||||
$bits=6;
|
||||
} elseif ($c >= 248) {
|
||||
$bits=5;
|
||||
} elseif ($c >= 240) {
|
||||
$bytes = 4;
|
||||
} elseif ($c >= 224) {
|
||||
$bytes = 3;
|
||||
} elseif ($c >= 192) {
|
||||
$bytes = 2;
|
||||
} else {
|
||||
return false;
|
||||
} if (($i + $bytes) > $len) {
|
||||
return false;
|
||||
} while ($bytes > 1) {
|
||||
$i++;
|
||||
$b = ord($content[$i]);
|
||||
if ($b < 128 || $b > 191) {
|
||||
return false;
|
||||
}
|
||||
$bytes--;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}//_checkUtf8Rfc3629()
|
||||
|
||||
/**
|
||||
* Splits a string to chunks of given size
|
||||
* This helps to avoid segmentation fault errors when large text is given
|
||||
* Returns array of strings after splitting
|
||||
*
|
||||
* @param string $str String to split.
|
||||
* @param int $len number of characters per chunk
|
||||
*
|
||||
* @return array string array after splitting
|
||||
*
|
||||
* @see http://php.net/manual/en/function.chunk-split.php
|
||||
*/
|
||||
private static function mb_chunk_split($str, $len, $glue)
|
||||
{
|
||||
if (empty($str)) return false;
|
||||
$array = self::mbStringToArray ($str);
|
||||
$n = -1;
|
||||
$new = Array();
|
||||
foreach ($array as $char) {
|
||||
$n++;
|
||||
if ($n < $len) $new []= $char;
|
||||
elseif ($n == $len) {
|
||||
$new []= $glue . $char;
|
||||
$n = 0;
|
||||
}
|
||||
}
|
||||
return $new;
|
||||
}//mb_chunk_split
|
||||
/**
|
||||
* Supporting function for mb_chunk_split
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @see http://php.net/manual/en/function.chunk-split.php
|
||||
*/
|
||||
private static function mbStringToArray ($str)
|
||||
{
|
||||
if (empty($str)) return false;
|
||||
$len = mb_strlen($str);
|
||||
$array = array();
|
||||
for ($i = 0; $i < $len; $i++) {
|
||||
$array[] = mb_substr($str, $i, 1);
|
||||
}
|
||||
return $array;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,81 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Operators_StrictComparisonOperatorSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Operators_StrictComparisonOperatorSniff.
|
||||
*
|
||||
* Ensures that only strict comparison operators are used instead of
|
||||
* equal and not equal operators.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Operators;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class StrictComparisonOperatorSniff implements Sniff
|
||||
{
|
||||
private static $_replacements = array(
|
||||
T_IS_EQUAL => '===',
|
||||
T_IS_NOT_EQUAL => '!==',
|
||||
);
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_IS_EQUAL,
|
||||
T_IS_NOT_EQUAL,
|
||||
);
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$operator_token = $tokens[$stackPtr];
|
||||
$operator_string = $operator_token['content'];
|
||||
$operator_code = $operator_token['code'];
|
||||
|
||||
$error_message = '"==" and "!=" are prohibited; use "'
|
||||
. self::$_replacements[$operator_code] . '" instead of "'
|
||||
. $operator_string . '".';
|
||||
$phpcsFile->addError($error_message, $stackPtr, 'NonStrictComparisonUsed');
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,465 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Strings;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use Exception;
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Strings_DoubleQuoteUsageSniff.
|
||||
*
|
||||
* Ensures that double-quoted strings are used only to parse variables,
|
||||
* to avoid escape characters before single quotes or for chars that need
|
||||
* to be interpreted like \r, \n or \t.
|
||||
* If a double-quoted string contain both single and double quotes
|
||||
* but no variable, then a warning is raised to encourage the use of
|
||||
* single-quoted strings.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class VariableUsageSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
/*
|
||||
return array(
|
||||
T_DOUBLE_QUOTED_STRING,
|
||||
T_CONSTANT_ENCAPSED_STRING,
|
||||
);
|
||||
*/
|
||||
return array();
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$string = $tokens[$stackPtr]['content'];
|
||||
// makes sure that it is about a double quote string,
|
||||
// since variables are not parsed out of double quoted string
|
||||
$openDblQtStr = substr($string, 0, 1);
|
||||
if (0 === strcmp($openDblQtStr, '"')) {
|
||||
$this->processDoubleQuotedString($phpcsFile, $stackPtr, $string);
|
||||
} else if (0 === strcmp($openDblQtStr, "'")) {
|
||||
$this->processSingleQuotedString($phpcsFile, $stackPtr, $string);
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when the token encountered is a double-quoted string.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $dblQtString The double-quoted string content,
|
||||
* i.e. without quotes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $dblQtString)
|
||||
{
|
||||
$variableFound = FALSE;
|
||||
$strTokens = token_get_all('<?php '.$dblQtString);
|
||||
$strPtr = 1; // skip php opening tag added by ourselves
|
||||
$requireDblQuotes = FALSE;
|
||||
while ($strPtr < count($strTokens)) {
|
||||
$strToken = $strTokens[$strPtr];
|
||||
if (is_array($strToken)) {
|
||||
if (in_array($strToken[0], array(T_DOLLAR_OPEN_CURLY_BRACES, T_CURLY_OPEN))) {
|
||||
$strPtr++;
|
||||
try {
|
||||
$this->_parseVariable($strTokens, $strPtr);
|
||||
} catch (Exception $err) {
|
||||
$error = 'There is no variable, object nor array between curly braces. Please use the escape char for $ or {.';
|
||||
$phpcsFile->addError($error, $stackPtr, 234);
|
||||
}
|
||||
$variableFound = TRUE;
|
||||
if ('}' !== $strTokens[$strPtr]) {
|
||||
$error = 'There is no matching closing curly brace.';
|
||||
$phpcsFile->addError($error, $stackPtr, 345);
|
||||
}
|
||||
// don't move forward, since it will be done in the main loop
|
||||
// $strPtr++;
|
||||
} else if (T_VARIABLE === $strToken[0]) {
|
||||
$variableFound = TRUE;
|
||||
$error = "Variable {$strToken[1]} in double-quoted strings should be enclosed with curly braces. Please consider {{$strToken[1]}}";
|
||||
$phpcsFile->addError($error, $stackPtr, 456);
|
||||
}
|
||||
}
|
||||
$strPtr++;
|
||||
}
|
||||
return $variableFound;
|
||||
}//end processDoubleQuotedString()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when the token encountered is a single-quoted string.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $sglQtString The single-quoted string content,
|
||||
* i.e. without quotes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $sglQtString)
|
||||
{
|
||||
$variableFound = FALSE;
|
||||
$strTokens = token_get_all('<?php '.$sglQtString);
|
||||
$strPtr = 1; // skip php opening tag added by ourselves
|
||||
while ($strPtr < count($strTokens)) {
|
||||
$strToken = $strTokens[$strPtr];
|
||||
if (is_array($strToken)) {
|
||||
if (T_VARIABLE === $strToken[0]) {
|
||||
$error = "Variables like {$strToken[1]} should be in double-quoted strings only.";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
}
|
||||
$strPtr++;
|
||||
}
|
||||
return $variableFound;
|
||||
}//end processSingleQuotedString()
|
||||
|
||||
/**
|
||||
* Grammar rule to parse the use of a variable. Please notice that it
|
||||
* doesn't manage the leading $.
|
||||
*
|
||||
* _parseVariable ::= <variable>
|
||||
* | <variable>_parseObjectAttribute()
|
||||
* | <variable>_parseArrayIndexes()
|
||||
*
|
||||
* @exception Exception raised if $strTokens starting from $strPtr
|
||||
* doesn't matched the rule.
|
||||
*
|
||||
* @param array $strTokens Tokens to parse.
|
||||
* @param int $strPtr Pointer to the token where parsing starts.
|
||||
*
|
||||
* @return array The attribute name associated to index 'var', an array with
|
||||
* indexes 'obj' and 'attr' or an array with indexes 'arr' and 'idx'.
|
||||
*/
|
||||
private function _parseVariable ($strTokens, &$strPtr)
|
||||
{
|
||||
if ( ! in_array($strTokens[$strPtr][0], array(T_VARIABLE, T_STRING_VARNAME))) {
|
||||
throw new Exception ('Expected variable name.');
|
||||
}
|
||||
$var = $strTokens[$strPtr][1];
|
||||
$strPtr++;
|
||||
$startStrPtr = $strPtr;
|
||||
try {
|
||||
$attr = $this->_parseObjectAttribute($strTokens, $strPtr);
|
||||
return array ('obj' => $var, 'attr' => $attr);
|
||||
} catch (Exception $err) {
|
||||
if ($strPtr !== $startStrPtr) {
|
||||
throw $err;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
|
||||
return array ('arr' => $var, 'idx' => $idx);
|
||||
} catch (Exception $err) {
|
||||
if ($strPtr !== $startStrPtr) {
|
||||
throw $err;
|
||||
}
|
||||
}
|
||||
return array ('var' => $var);
|
||||
}//end _parseVariable()
|
||||
|
||||
|
||||
/**
|
||||
* Grammar rule to parse the use of an object attribute.
|
||||
*
|
||||
* _parseObjectAttribute ::= -><attribute>
|
||||
* | -><attribute>_parseObjectAttribute()
|
||||
* | -><attribute>_parseArrayIndexes()
|
||||
*
|
||||
* @exception Exception raised if $strTokens starting from $strPtr
|
||||
* doesn't matched the rule.
|
||||
*
|
||||
* @param array $strTokens Tokens to parse.
|
||||
* @param int $strPtr Pointer to the token where parsing starts.
|
||||
*
|
||||
* @return mixed The attribute name as a string, an array with indexes
|
||||
* 'obj' and 'attr' or an array with indexes 'arr' and 'idx'.
|
||||
*/
|
||||
private function _parseObjectAttribute ($strTokens, &$strPtr)
|
||||
{
|
||||
if (T_OBJECT_OPERATOR !== $strTokens[$strPtr][0]) {
|
||||
throw new Exception ('Expected ->.');
|
||||
}
|
||||
$strPtr++;
|
||||
if (T_STRING !== $strTokens[$strPtr][0]) {
|
||||
throw new Exception ('Expected an object attribute.');
|
||||
}
|
||||
$attr = $strTokens[$strPtr][1];
|
||||
$strPtr++;
|
||||
$startStrPtr = $strPtr;
|
||||
try {
|
||||
$sub_attr = $this->_parseObjectAttribute($strTokens, $strPtr);
|
||||
return array ('obj' => $attr, 'attr' => $sub_attr);
|
||||
} catch (Exception $err) {
|
||||
if ($strPtr !== $startStrPtr) {
|
||||
throw $err;
|
||||
}
|
||||
}
|
||||
try {
|
||||
$idx = $this->_parseArrayIndexes($strTokens, $strPtr);
|
||||
return array ('arr' => $attr, 'idx' => $idx);
|
||||
} catch (Exception $err) {
|
||||
if ($strPtr !== $startStrPtr) {
|
||||
throw $err;
|
||||
}
|
||||
}
|
||||
return $attr;
|
||||
}//end _parseObjectAttribute()
|
||||
|
||||
|
||||
/**
|
||||
* Grammar rule to parse the use of one or more array indexes.
|
||||
*
|
||||
* _parseArrayIndexes ::= _parseArrayIndex()+
|
||||
*
|
||||
* @exception Exception raised if $strTokens starting from $strPtr
|
||||
* doesn't matched the rule.
|
||||
*
|
||||
* @param array $strTokens Tokens to parse.
|
||||
* @param int $strPtr Pointer to the token where parsing starts.
|
||||
*
|
||||
* @return array Indexes in the same order as in the string.
|
||||
*/
|
||||
private function _parseArrayIndexes ($strTokens, &$strPtr)
|
||||
{
|
||||
$indexes = array($this->_parseArrayIndex($strTokens, $strPtr));
|
||||
try {
|
||||
while (1) {
|
||||
$startStrPtr = $strPtr;
|
||||
$indexes [] = $this->_parseArrayIndex($strTokens, $strPtr);
|
||||
}
|
||||
} catch (Exception $err) {
|
||||
if (0 !== ($strPtr - $startStrPtr)) {
|
||||
throw $err;
|
||||
}
|
||||
return $indexes;
|
||||
}
|
||||
}//end _parseArrayIndexes()
|
||||
|
||||
|
||||
/**
|
||||
* Grammar rule to parse the use of array index.
|
||||
*
|
||||
* _parseArrayIndex ::= [<index>]
|
||||
*
|
||||
* @exception Exception raised if $strTokens starting from $strPtr
|
||||
* doesn't matched the rule.
|
||||
*
|
||||
* @param array $strTokens Tokens to parse.
|
||||
* @param int $strPtr Pointer to the token where parsing starts.
|
||||
*
|
||||
* @return string Index between the 2 square brackets
|
||||
*/
|
||||
private function _parseArrayIndex ($strTokens, &$strPtr)
|
||||
{
|
||||
if ('[' !== $strTokens[$strPtr]) {
|
||||
throw new Exception ('Expected [.');
|
||||
}
|
||||
$strPtr++;
|
||||
if (! in_array($strTokens[$strPtr][0], array(T_CONSTANT_ENCAPSED_STRING, T_LNUMBER))) {
|
||||
throw new Exception ('Expected an array index.');
|
||||
}
|
||||
$index = $strTokens[$strPtr][1];
|
||||
$strPtr++;
|
||||
if (']' !== $strTokens[$strPtr]) {
|
||||
throw new Exception ('Expected ].');
|
||||
}
|
||||
$strPtr++;
|
||||
return $index;
|
||||
}//end _parseArrayIndex()
|
||||
|
||||
}//end class
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Strings_VariableUsageSniff.
|
||||
*
|
||||
* Ensures that variables parsed in double-quoted strings are enclosed with
|
||||
* braces to prevent greedy token parsing.
|
||||
* Single-quoted strings don't parse variables, so there is no risk of greedy
|
||||
* token parsing.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class DoubleQuoteUsageSniff extends VariableUsageSniff
|
||||
{
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_DOUBLE_QUOTED_STRING,
|
||||
T_CONSTANT_ENCAPSED_STRING,
|
||||
);
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// no variable are in the string from here
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$qtString = $tokens[$stackPtr]['content'];
|
||||
// makes sure that it is about a double quote string,
|
||||
// since variables are not parsed out of double quoted string
|
||||
$open_qt_str = substr($qtString, 0, 1);
|
||||
|
||||
// clean the enclosing quotes
|
||||
$qtString = substr($qtString, 1, strlen($qtString) - 1 - 1);
|
||||
|
||||
if (0 === strcmp($open_qt_str, '"')) {
|
||||
$this->processDoubleQuotedString($phpcsFile, $stackPtr, $qtString);
|
||||
} else if (0 === strcmp($open_qt_str, "'")) {
|
||||
$this->processSingleQuotedString($phpcsFile, $stackPtr, $qtString);
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when the token encountered is a double-quoted string.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $qtString The double-quoted string content,
|
||||
* i.e. without quotes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processDoubleQuotedString (File $phpcsFile, $stackPtr, $qtString)
|
||||
{
|
||||
// so there should be at least a single quote or a special char
|
||||
// if there are the 2 kinds of quote and no special char, then add a warning
|
||||
$has_variable = parent::processDoubleQuotedString($phpcsFile, $stackPtr, '"'.$qtString.'"');
|
||||
$has_specific_sequence = $this->_hasSpecificSequence($qtString);
|
||||
$dbl_qt_at = strpos($qtString, '"');
|
||||
$smpl_qt_at = strpos($qtString, "'");
|
||||
if (false === $has_variable && false === $has_specific_sequence
|
||||
&& false === $smpl_qt_at
|
||||
) {
|
||||
$error = 'Single-quoted strings should be used unless it contains variables, special chars like \n or single quotes.';
|
||||
$phpcsFile->addError($error, $stackPtr, 111);
|
||||
} else if (false !== $smpl_qt_at && false !== $dbl_qt_at
|
||||
&& false === $has_variable && false === $has_specific_sequence
|
||||
) {
|
||||
$warning = 'It is encouraged to use a single-quoted string, since it doesn\'t contain any variable nor special char though it mixes single and double quotes.';
|
||||
$phpcsFile->addWarning($warning, $stackPtr, 222);
|
||||
}
|
||||
}//end processDoubleQuotedString()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when the token encountered is a single-quoted string.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $qtString The single-quoted string content,
|
||||
* i.e. without quotes.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processSingleQuotedString (File $phpcsFile, $stackPtr, $qtString)
|
||||
{
|
||||
// if there is single quotes without additional double quotes,
|
||||
// then user is allowed to use double quote to avoid having to
|
||||
// escape single quotes. Don't add the warning, if an error was
|
||||
// already added, because a variable was found in a single-quoted
|
||||
// string.
|
||||
$has_variable = parent::processSingleQuotedString($phpcsFile, $stackPtr, "'".$qtString."'");
|
||||
$dbl_qt_at = strpos($qtString, '"');
|
||||
$smpl_qt_at = strpos($qtString, "'");
|
||||
if (false === $has_variable && false !== $smpl_qt_at && false === $dbl_qt_at) {
|
||||
$warning = 'You may also use double-quoted strings if the string contains single quotes, so you do not have to use escape characters.';
|
||||
$phpcsFile->addWarning($warning, $stackPtr, 333);
|
||||
}
|
||||
}//end processSingleQuotedString()
|
||||
|
||||
/**
|
||||
* Return TRUE, if a sequence of chars that is parsed in a specific way
|
||||
* in double-quoted strings is found, FALSE otherwise.
|
||||
*
|
||||
* @param string $string String in which sequence of special chars will
|
||||
* be researched.
|
||||
*
|
||||
* @return TRUE, if a sequence of chars that is parsed in a specific way
|
||||
* in double-quoted strings is found, FALSE otherwise.
|
||||
*
|
||||
* @link http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double
|
||||
*/
|
||||
private function _hasSpecificSequence($string)
|
||||
{
|
||||
$hasSpecificSequence = FALSE;
|
||||
$specialMeaningStrs = array('\n', '\r', '\t', '\v', '\f');
|
||||
foreach ($specialMeaningStrs as $splStr) {
|
||||
if (FALSE !== strpos($string, $splStr)) {
|
||||
$hasSpecificSequence = TRUE;
|
||||
}
|
||||
}
|
||||
$specialMeaningPtrns = array('\[0-7]{1,3}', '\x[0-9A-Fa-f]{1,2}');
|
||||
foreach ($specialMeaningPtrns as $splPtrn) {
|
||||
if (1 === preg_match("/{$splPtrn}/", $string)) {
|
||||
$hasSpecificSequence = TRUE;
|
||||
}
|
||||
}
|
||||
return $hasSpecificSequence;
|
||||
}//end _hasSpecificSequence()
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,87 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@gmail.com>
|
||||
* @copyright 2011 Thomas ERNEST
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_DisallowSpaceIndentSniff.
|
||||
*
|
||||
* Ensures the use of tabs for indentation.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@gmail.com>
|
||||
* @copyright 2011 Thomas ERNEST
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class DisallowSpaceIndentSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* A list of tokenizers this sniff supports.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public $supportedTokenizers = array(
|
||||
'PHP',
|
||||
'JS',
|
||||
'CSS',
|
||||
);
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(T_WHITESPACE);
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile All the tokens found in the document.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
// Make sure this is whitespace used for indentation.
|
||||
$line = $tokens[$stackPtr]['line'];
|
||||
if ($stackPtr > 0 && $tokens[($stackPtr - 1)]['line'] === $line) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (strpos($tokens[$stackPtr]['content'], " ") !== false) {
|
||||
$error = 'Tabs must be used to indent lines; spaces are not allowed for code indentation';
|
||||
$phpcsFile->addError($error, $stackPtr, 'SpacesUsedForIndentation');
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,95 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_DisallowWitheSpaceAroundPhpTagsSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_DisallowWitheSpaceAroundPhpTagsSniff.
|
||||
*
|
||||
* Ensures that no whitespace precedes the opening PHP tag
|
||||
* or follows the closing PHP tag.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class DisallowWitheSpaceAroundPhpTagsSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_OPEN_TAG,
|
||||
T_CLOSE_TAG
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$php_tag_token = $tokens[$stackPtr];
|
||||
$php_tag_code = $php_tag_token['code'];
|
||||
|
||||
if (T_OPEN_TAG === $php_tag_code) {
|
||||
// opening php tag should be the first token.
|
||||
// any whitespace beofre an opening php tag is tokenized
|
||||
// as T_INLINE_HTML, so no need to check the content of the token.
|
||||
$isFirst = 0 === $stackPtr;
|
||||
if ( ! $isFirst) {
|
||||
$error = 'Any char before the opening PHP tag is prohibited. Please remove newline or indentation before the opening PHP tag.';
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
} else {
|
||||
// if (T_CLOSE_TAG === $php_tag_code)
|
||||
// closing php tag should be the last token
|
||||
// and it must not contain any whitespace.
|
||||
$php_tag_string = $php_tag_token['content'];
|
||||
$isLast = count($tokens) - 1 === $stackPtr;
|
||||
// both of the two closing php tags contains 2 chars exactly.
|
||||
$containsEndTagOnly = strlen($php_tag_string) > 2;
|
||||
if ( ! $isLast || ! $containsEndTagOnly ) {
|
||||
$error = 'Any char after the closing PHP tag is prohibited. Please removes newline or spaces after the closing PHP tag.';
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,82 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_ElseOnNewLineSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_ElseOnNewLineSniff.
|
||||
*
|
||||
* Ensures that control structures else and elseif stand on new lines.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ElseOnNewLineSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_ELSE,
|
||||
T_ELSEIF,
|
||||
);
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$else_token = $tokens[$stackPtr];
|
||||
$previous_non_blank_token_ptr = $phpcsFile->findPrevious(array(T_WHITESPACE), $stackPtr - 1, null, true);
|
||||
|
||||
if (false === $previous_non_blank_token_ptr) {
|
||||
// else is no preceded with any symbol, but it is not the responsibility of this sniff.
|
||||
return;
|
||||
}
|
||||
|
||||
$previous_non_blank_token = $tokens[$previous_non_blank_token_ptr];
|
||||
if ($previous_non_blank_token['line'] === $else_token['line']) {
|
||||
$error = '"' . $else_token['content'] . '" should be on a new line.';
|
||||
$phpcsFile->addError($error, $stackPtr, 123423);
|
||||
}
|
||||
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,75 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_LogicalNotSpacingSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_WhiteSpace_LogicalNotSpacingSniff.
|
||||
*
|
||||
* Ensures that at exactly a space precedes and follows the logical operator !.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\WhiteSpace;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class LogicalNotSpacingSniff implements Sniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_BOOLEAN_NOT,
|
||||
);
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$operator_token = $tokens[$stackPtr];
|
||||
|
||||
$previous_token = $tokens[$stackPtr - 1];
|
||||
$next_token = $tokens[$stackPtr + 1];
|
||||
if (T_WHITESPACE !== $previous_token['code'] || T_WHITESPACE !== $next_token['code']) {
|
||||
$error = 'Logical operator ! should always be preceded and followed with a whitespace.';
|
||||
$phpcsFile->addError($error, $stackPtr, 'badNot');
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,104 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_AbstractClosingCommentSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_AbstractClosingCommentSniff.
|
||||
*
|
||||
* Defines some methods used by
|
||||
* CodeIgniter_Sniffs_Files_ClosingFileCommentSniff
|
||||
* and CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Files;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class AbstractClosingCommentSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* As an abstract class, this sniff is not associated to any token.
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* As an abstract class, this sniff is not dedicated to process a token.
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$error = __CLASS__.'::'.__METHOD__.' is abstract. Please develop this method in a child class.';
|
||||
throw new PHP_CodeSniffer_Exception($error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the comment without its delimiter(s) as well as leading
|
||||
* and traling whitespaces.
|
||||
*
|
||||
* It removes the first #, the two first / (i.e. //) or the first /*
|
||||
* and last \*\/. If a comment starts with /**, then the last * will remain
|
||||
* as well as whitespaces between this star and the comment content.
|
||||
*
|
||||
* @param string $comment Comment containing either comment delimiter(s) and
|
||||
* trailing or leading whitspaces to clean.
|
||||
*
|
||||
* @return string Comment without comment delimiter(s) and whitespaces.
|
||||
*/
|
||||
protected static function _getCommentContent ($comment)
|
||||
{
|
||||
if (self::_stringStartsWith($comment, '#')) {
|
||||
$comment = substr($comment, 1);
|
||||
} else if (self::_stringStartsWith($comment, '//')) {
|
||||
$comment = substr($comment, 2);
|
||||
} else if (self::_stringStartsWith($comment, '/*')) {
|
||||
$comment = substr($comment, 2, strlen($comment) - 2 - 2);
|
||||
}
|
||||
$comment = trim($comment);
|
||||
return $comment;
|
||||
}//_getCommentContent()
|
||||
|
||||
|
||||
/**
|
||||
* Binary safe string comparison between $needle and
|
||||
* the beginning of $haystack. Returns true if $haystack starts with
|
||||
* $needle, false otherwise.
|
||||
*
|
||||
* @param string $haystack The string to search in.
|
||||
* @param string $needle The string to search for.
|
||||
*
|
||||
* @return bool true if $haystack starts with $needle, false otherwise.
|
||||
*/
|
||||
protected static function _stringStartsWith ($haystack, $needle)
|
||||
{
|
||||
$startsWith = false;
|
||||
if (strlen($needle) <= strlen($haystack)) {
|
||||
$haystackBeginning = substr($haystack, 0, strlen($needle));
|
||||
if (0 === strcmp($haystackBeginning, $needle)) {
|
||||
$startsWith = true;
|
||||
}
|
||||
}
|
||||
return $startsWith;
|
||||
}//_stringStartsWith()
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,109 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_ClosingFileCommentSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_ClosingFileCommentSniff.
|
||||
*
|
||||
* Ensures that a comment containing the file name is available at the end of file.
|
||||
* Only other comments and whitespaces are allowed to follow this specific comment.
|
||||
*
|
||||
* It may be all kind of comment like multi-line and inline C-style comments as
|
||||
* well as PERL-style comments. Any number of white may separate comment delimiters
|
||||
* from comment content. However, content has to be equal to template
|
||||
* "End of file <file_name>". Comparison between content and template is
|
||||
* case-sensitive.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Files;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ClosingFileCommentSniff extends AbstractClosingCommentSniff
|
||||
{
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_OPEN_TAG,
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We are only interested if this is the first open tag.
|
||||
if ($stackPtr !== 0) {
|
||||
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$fullFilename = $phpcsFile->getFilename();
|
||||
$filename = basename($fullFilename);
|
||||
$commentTemplate = "End of file $filename";
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$currentToken = count($tokens) - 1;
|
||||
$hasClosingFileComment = false;
|
||||
$isNotAWhitespaceOrAComment = false;
|
||||
while ($currentToken >= 0
|
||||
&& ! $isNotAWhitespaceOrAComment
|
||||
&& ! $hasClosingFileComment
|
||||
) {
|
||||
$token = $tokens[$currentToken];
|
||||
$tokenCode = $token['code'];
|
||||
if (T_COMMENT === $tokenCode) {
|
||||
$commentString = self::_getCommentContent($token['content']);
|
||||
if (0 === strcmp($commentString, $commentTemplate)) {
|
||||
$hasClosingFileComment = true;
|
||||
}
|
||||
} else if (T_WHITESPACE === $tokenCode) {
|
||||
// Whitespaces are allowed between the closing file comment,
|
||||
// other comments and end of file
|
||||
} else {
|
||||
$isNotAWhitespaceOrAComment = true;
|
||||
}
|
||||
$currentToken--;
|
||||
}
|
||||
|
||||
if ( ! $hasClosingFileComment) {
|
||||
$error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
|
||||
$phpcsFile->addError($error, $currentToken);
|
||||
}
|
||||
}//end process()
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,182 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff.
|
||||
*
|
||||
* Ensures that a comment containing the file location exists at the end of file.
|
||||
* Only other comments and whitespaces are allowed between this comment and
|
||||
* the end of file.
|
||||
*
|
||||
* It may be all kind of comment like multi-line and inline C-style comments as
|
||||
* well as PERL-style comments. Any number of white may separate comment delimiters
|
||||
* from comment content. However, content has to be equal to template
|
||||
* "Location: <file_path_relative_to_application_root>".
|
||||
* Comparison between content and template is case-sensitive.
|
||||
*
|
||||
* There are several ways to configure the application root. In order of priority :
|
||||
* - Configuration variable ci_application_root.
|
||||
* - Rule property applicationRoot.
|
||||
* - Default value '/application/'
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2006 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\Files;
|
||||
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
use PHP_CodeSniffer\Util\Common;
|
||||
|
||||
class ClosingLocationCommentSniff extends AbstractClosingCommentSniff
|
||||
{
|
||||
public $applicationRoot = '/application/';
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_OPEN_TAG
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// We are only interested if this is the first open tag.
|
||||
if ($stackPtr !== 0) {
|
||||
if ($phpcsFile->findPrevious(T_OPEN_TAG, ($stackPtr - 1)) !== false) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$filePath = $phpcsFile->getFilename();
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
// removes the application root from the beginning of the file path
|
||||
$locationPath = self::_getLocationPath($filePath, $this->_getAppRoot());
|
||||
// add an error, if application root doesn't exist in current file path
|
||||
if (false === $locationPath) {
|
||||
$error = 'Unable to find "' . $this->_getAppRoot() . '" in file path "' . $filePath . '". Please set your project\'s application root.';
|
||||
$phpcsFile->addError($error, count($tokens) - 1);
|
||||
return;
|
||||
}
|
||||
// generates the expected comment
|
||||
$commentTemplate = "Location: $locationPath";
|
||||
|
||||
$currentToken = count($tokens) - 1;
|
||||
$hasClosingLocationComment = false;
|
||||
$isNotAWhitespaceOrAComment = false;
|
||||
while ($currentToken >= 0
|
||||
&& ! $isNotAWhitespaceOrAComment
|
||||
&& ! $hasClosingLocationComment
|
||||
) {
|
||||
$token = $tokens[$currentToken];
|
||||
$tokenCode = $token['code'];
|
||||
if (T_COMMENT === $tokenCode) {
|
||||
$commentString = self::_getCommentContent($token['content']);
|
||||
if (0 === strcmp($commentString, $commentTemplate)) {
|
||||
$hasClosingLocationComment = true;
|
||||
}
|
||||
} else if (T_WHITESPACE === $tokenCode) {
|
||||
// Whitespaces are allowed between the closing file comment,
|
||||
//other comments and end of file
|
||||
} else {
|
||||
$isNotAWhitespaceOrAComment = true;
|
||||
}
|
||||
$currentToken--;
|
||||
}
|
||||
|
||||
if ( ! $hasClosingLocationComment) {
|
||||
$error = 'No comment block marks the end of file instead of the closing PHP tag. Please add a comment block containing only "' . $commentTemplate . '".';
|
||||
$phpcsFile->addError($error, $currentToken);
|
||||
}
|
||||
}//end process()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the relative path from $appRoot to $filePath, or false if
|
||||
* $appRoot cannot be found in $filePath, because $appRoot is not a parent
|
||||
* of $filePath.
|
||||
*
|
||||
* @param string $filePath Full path to the file being proceed.
|
||||
* @param string $appRoot Partial or full path to the CodeIgniter
|
||||
* application root of the file being proceed. It must not contain the
|
||||
* full path to the application root, but at least the name of the
|
||||
* application root. Parent directory of the application root are allowed
|
||||
* but not mandatory.
|
||||
*
|
||||
* @return string|bool The relative path from $appRoot to $filePath, or
|
||||
* false if $appRoot cannot be found in $filePath.
|
||||
*/
|
||||
private static function _getLocationPath ($filePath, $appRoot)
|
||||
{
|
||||
// removes the path to application root
|
||||
// from the beginning of the file path
|
||||
$appRootAt = strpos($filePath, $appRoot);
|
||||
if (false === $appRootAt) {
|
||||
return false;
|
||||
}
|
||||
$localPath = substr($filePath, $appRootAt + strlen($appRoot));
|
||||
// ensures the location path to be a relative path starting with "./".
|
||||
if ( ! self::_stringStartsWith($localPath, './')) {
|
||||
$localPath = './' . $localPath;
|
||||
} else if ( ! self::_stringStartsWith($localPath, '.')
|
||||
&& self::_stringStartsWith($localPath, '/')
|
||||
) {
|
||||
$localPath = '.' . $localPath;
|
||||
}
|
||||
return $localPath;
|
||||
}//end _getLocationPath()
|
||||
|
||||
|
||||
/**
|
||||
* Returns the application root that should be used first.
|
||||
*
|
||||
* There are several ways to configure the application root.
|
||||
* In order of priority :
|
||||
* - Configuration variable ci_application_root.
|
||||
* - Rule property applicationRoot.
|
||||
* - Default value '/application/'
|
||||
*
|
||||
* @return string Path to your project application root.
|
||||
*/
|
||||
private function _getAppRoot()
|
||||
{
|
||||
$appRoot = Common::getConfigData('ci_application_root');
|
||||
if (null === $appRoot) {
|
||||
$appRoot = $this->applicationRoot;
|
||||
}
|
||||
return $appRoot;
|
||||
}//end _getAppRoot()
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,142 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ConstructorNameSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@gmail.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\NamingConventions;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\AbstractScopeSniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ConstructorNameSniff.
|
||||
*
|
||||
* Favor PHP 4 constructor syntax, which uses "function ClassName()".
|
||||
* Avoid PHP 5 constructor syntax, which uses "function __construct()".
|
||||
*
|
||||
* @todo Try to avoid overly long and verbose names.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@gmail.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
class ConstructorNameSniff extends AbstractScopeSniff
|
||||
{
|
||||
|
||||
|
||||
public $php5Constructors = '1';
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the test with the tokens it wishes to listen for.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param int $currScope A pointer to the start of the scope.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processTokenWithinScope(
|
||||
File $phpcsFile,
|
||||
$stackPtr,
|
||||
$currScope
|
||||
) {
|
||||
$methodName = $phpcsFile->getDeclarationName($stackPtr);
|
||||
$className = $phpcsFile->getDeclarationName($currScope);
|
||||
|
||||
$isPhp4Constructor = strcasecmp($methodName, $className) === 0;
|
||||
$isPhp5Constructor = strcasecmp($methodName, '__construct') === 0;
|
||||
if ($this->php5Constructors != '0') {
|
||||
if ($isPhp4Constructor) {
|
||||
$error = "PHP4 style constructors are not allowed; use \"__construct\" instead";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
} else {
|
||||
if ($isPhp5Constructor) {
|
||||
$error = "PHP5 style constructors are not allowed; use \"$className\" instead";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
}
|
||||
if ( ! $isPhp4Constructor && ! $isPhp5Constructor ) {
|
||||
return;
|
||||
}
|
||||
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
|
||||
$parentClassName = $phpcsFile->findExtendedClassName($currScope);
|
||||
$wrongConstructor = '';
|
||||
// prepares the error message and wrong constructor
|
||||
if ($this->php5Constructors != '0') {
|
||||
$error = 'PHP4 style calls to parent constructors are not allowed.';
|
||||
$error = "$error Please use \"parent::__construct\" instead.";
|
||||
if (false !== $parentClassName) {
|
||||
$wrongConstructor = $parentClassName;
|
||||
}
|
||||
// Else $wrongConstructor will be empty
|
||||
// and the test expression will always be false.
|
||||
// It doesn't check that no parent method should be called
|
||||
// when no parent class is defined.
|
||||
} else {
|
||||
$error = 'PHP5 style calls to parent constructors are not allowed.';
|
||||
if (false !== $parentClassName) {
|
||||
$error = "$error Please use \"parent::$parentClassName\" instead.";
|
||||
}
|
||||
$wrongConstructor = '__construct';
|
||||
}
|
||||
|
||||
// looks for the use of a wrong constructor.
|
||||
$endFunctionIndex = $tokens[$stackPtr]['scope_closer'];
|
||||
$doubleColonIndex = $phpcsFile->findNext(
|
||||
array(T_DOUBLE_COLON),
|
||||
$stackPtr,
|
||||
$endFunctionIndex
|
||||
);
|
||||
while ($doubleColonIndex) {
|
||||
if ($tokens[($doubleColonIndex + 1)]['code'] === T_STRING
|
||||
&& $tokens[($doubleColonIndex + 1)]['content'] === $wrongConstructor
|
||||
) {
|
||||
$phpcsFile->addError($error, ($doubleColonIndex + 1));
|
||||
}
|
||||
|
||||
$doubleColonIndex = $phpcsFile->findNext(
|
||||
array(T_DOUBLE_COLON),
|
||||
$doubleColonIndex + 1,
|
||||
$endFunctionIndex
|
||||
);
|
||||
}
|
||||
|
||||
}//end processTokenWithinScope()
|
||||
|
||||
protected function processTokenOutsideScope(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// TODO: Implement processTokenOutsideScope() method.
|
||||
}
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidClassNameSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baoabz.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidClassNameSniff.
|
||||
*
|
||||
* Ensures that class and interface names have their first letter uppercase
|
||||
* and that words are separated with an underscore, and not CamelCased.
|
||||
*
|
||||
* @todo Try to avoid overly long and verbose names in using property rule and
|
||||
* configuration variable to set limits. Have a look at
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidMethodNameSniff.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baoabz.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\NamingConventions;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ValidClassNameSniff implements Sniff
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_CLASS,
|
||||
T_INTERFACE,
|
||||
);
|
||||
|
||||
}//end register()
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// get the class name
|
||||
$className = trim($phpcsFile->getDeclarationName($stackPtr));
|
||||
// compute the expected class name
|
||||
// [^_] means "something different from _", but not "nothing or something different from _"
|
||||
$lcClassNameChunk = preg_replace('/([^_])([A-Z])/', '${1}_${2}', $className);
|
||||
$expectedClassName
|
||||
= strtoupper($className[0]) . strtolower(substr($lcClassNameChunk,1));
|
||||
// ensures that the current class name
|
||||
// and the expected class name are identical
|
||||
if (0 !== strcmp($className, $expectedClassName)) {
|
||||
$error = 'Class names should always have their first letter uppercase. Multiple words should be separated with an underscore, and not CamelCased. Please consider ' . $expectedClassName . ' instead of ' . $className . '.';
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
}//end process()
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,84 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidFileNameSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidFileNameSniff.
|
||||
*
|
||||
* Tests that the file name matchs the name of the class that it contains in lower case.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baobaz.com>
|
||||
* @copyright 2011 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\NamingConventions;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\Sniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ValidFileNameSniff implements Sniff
|
||||
{
|
||||
/**
|
||||
* Returns an array of tokens this test wants to listen for.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function register()
|
||||
{
|
||||
return array(
|
||||
T_CLASS,
|
||||
T_INTERFACE,
|
||||
);
|
||||
}//end register()
|
||||
|
||||
|
||||
/**
|
||||
* Processes this test, when one of its tokens is encountered.
|
||||
*
|
||||
* @param File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token in the
|
||||
* stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function process(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
// computes the expected filename based on the name of the class or interface that it contains.
|
||||
$decNamePtr = $phpcsFile->findNext(T_STRING, $stackPtr);
|
||||
$decName = $tokens[$decNamePtr]['content'];
|
||||
$expectedFileName = strtolower($decName);
|
||||
// extracts filename without extension from its path.
|
||||
$fullPath = $phpcsFile->getFilename();
|
||||
$fileNameAndExt = basename($fullPath);
|
||||
$fileName = substr($fileNameAndExt, 0, strrpos($fileNameAndExt, '.'));
|
||||
|
||||
if ($expectedFileName !== $fileName) {
|
||||
$errorTemplate = 'Filename "%s" doesn\'t match the name of the %s that it contains "%s" in lower case. "%s" was expected.';
|
||||
$errorMessage = sprintf(
|
||||
$errorTemplate,
|
||||
$fileName,
|
||||
strtolower($tokens[$stackPtr]['content']), // class or interface
|
||||
$decName,
|
||||
$expectedFileName
|
||||
);
|
||||
$phpcsFile->addError($errorMessage, 0);
|
||||
}
|
||||
}//end process()
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,161 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidMethodNameSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baoabz.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidMethodNameSniff.
|
||||
*
|
||||
* Ensures that class methods and functions areentirely lowercased and that
|
||||
* words are separated with an underscore, and not CamelCased.
|
||||
* Ensures that private class methods are prefixed with an underscore and that
|
||||
* all other methods are not prefixed with an underscored.
|
||||
* Ensures that names longer than 50 chars are prohibited. Likewise names longer
|
||||
* than 35 chars raise a warning.
|
||||
*
|
||||
* @todo Use a rule property or a configuration variable to allow users to set
|
||||
* their own maximum lengths for function and method names. Have a look at
|
||||
* CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff and application root.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baoabz.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
|
||||
namespace CodeIgniter\Sniffs\NamingConventions;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\AbstactScopeSniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ValidMethodNameSniff extends AbstractScopeSniff
|
||||
{
|
||||
/**
|
||||
* A list of all PHP magic methods.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected static $magicMethods = array(
|
||||
'construct',
|
||||
'destruct',
|
||||
'call',
|
||||
'callStatic',
|
||||
'get',
|
||||
'set',
|
||||
'isset',
|
||||
'unset',
|
||||
'sleep',
|
||||
'wakeup',
|
||||
'toString',
|
||||
'set_state',
|
||||
'clone',
|
||||
);
|
||||
|
||||
/**
|
||||
* Defines which token(s) in which scope(s) will be proceed.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(array(T_CLASS, T_INTERFACE), array(T_FUNCTION), true);
|
||||
|
||||
}//end __construct()
|
||||
|
||||
|
||||
/**
|
||||
* Processes the tokens within the scope.
|
||||
*
|
||||
* @param File $phpcsFile The file being processed.
|
||||
* @param int $stackPtr The position where this token was
|
||||
* found.
|
||||
* @param int $currScope The position of the current scope.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processTokenWithinScope(File $phpcsFile, $stackPtr, $currScope)
|
||||
{
|
||||
$methodName = $phpcsFile->getDeclarationName($stackPtr);
|
||||
if ($methodName === null) {
|
||||
// Ignore closures.
|
||||
return;
|
||||
}
|
||||
|
||||
$className = $phpcsFile->getDeclarationName($currScope);
|
||||
|
||||
// Is this a magic method i.e. is prefixed with "__".
|
||||
if (0 === strcmp(substr($methodName, 0, 2), '__')) {
|
||||
$magicPart = substr($methodName, 2);
|
||||
if (in_array($magicPart, self::$magicMethods) === false) {
|
||||
$error = "Method name \"$className::$methodName\" is invalid; only PHP magic methods should be prefixed with a double underscore";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// PHP4 constructors are allowed to break our rules.
|
||||
if ($methodName === $className) {
|
||||
return;
|
||||
}
|
||||
|
||||
// PHP4 destructors are allowed to break our rules.
|
||||
if ($methodName === '_'.$className) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (0 !== strcmp($methodName, strtolower($methodName))) {
|
||||
$uscrdMethodName = preg_replace('/([A-Z])/', '_${1}', $methodName);
|
||||
$expectedMethodName = strtolower($uscrdMethodName);
|
||||
$error = "Class methods should be entirely lowercased. Please consider \"$expectedMethodName\" instead of \"$methodName\".";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
$methodProps = $phpcsFile->getMethodProperties($stackPtr);
|
||||
$scope = $methodProps['scope'];
|
||||
$scopeSpecified = $methodProps['scope_specified'];
|
||||
|
||||
// If it's a private method, it must have an underscore on the front.
|
||||
if ($scope === 'private' && $methodName{0} !== '_') {
|
||||
$error = "Private method name \"$className::$methodName\" must be prefixed with an underscore";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
// If it's not a private method, it must not have an underscore on the front.
|
||||
if ($scope !== 'private' && $methodName{0} === '_') {
|
||||
if (true === $scopeSpecified) {
|
||||
$error = "Public method name \"$className::$methodName\" must not be prefixed with an underscore";
|
||||
} else {
|
||||
$error = ucfirst($scope)." method name \"$className::$methodName\" must not be prefixed with an underscore";
|
||||
}
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
return;
|
||||
}
|
||||
|
||||
// If name is too verbose,
|
||||
// then either an error or a warning is displayed.
|
||||
$error_limit = 50;
|
||||
$warning_limit = 35;
|
||||
if (strlen($methodName) > $error_limit) {
|
||||
$error = "Overly long and verbose names are prohibited. Please find a name shorter than $error_limit chars.";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
return;
|
||||
} else if (strlen($methodName) > $warning_limit) {
|
||||
$warning = "Try to avoid overly long and verbose names in finding a name shorter than $warning_limit chars.";
|
||||
$phpcsFile->addWarning($warning, $stackPtr);
|
||||
}
|
||||
}//end processTokenWithinScope()
|
||||
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,562 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidVariableNameSniff.
|
||||
*
|
||||
* PHP version 5
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baoabz.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
/**
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidVariableNameSniff.
|
||||
*
|
||||
* Ensures that variable names contain only lowercase letters,
|
||||
* use underscore separators.
|
||||
* Ensures that class attribute names are prefixed with an underscore,
|
||||
* only when they are private.
|
||||
* Ensure that variable names are longer than 3 chars except those declared
|
||||
* in for loops.
|
||||
*
|
||||
* @todo Try to avoid overly long and verbose names in using property rule and
|
||||
* configuration variable to set limits. Have a look at
|
||||
* CodeIgniter_Sniffs_NamingConventions_ValidMethodNameSniff.
|
||||
* @todo Use a property rule or a configuration variable to allow users to set
|
||||
* minimum variable name length. Have a look at
|
||||
* CodeIgniter_Sniffs_Files_ClosingLocationCommentSniff and application root.
|
||||
*
|
||||
* @category PHP
|
||||
* @package PHP_CodeSniffer
|
||||
* @author Thomas Ernest <thomas.ernest@baoabz.com>
|
||||
* @copyright 2010 Thomas Ernest
|
||||
* @license http://thomas.ernest.fr/developement/php_cs/licence GNU General Public License
|
||||
* @link http://pear.php.net/package/PHP_CodeSniffer
|
||||
*/
|
||||
namespace CodeIgniter\Sniffs\NamingConventions;
|
||||
|
||||
use PHP_CodeSniffer\Sniffs\AbstractVariableSniff;
|
||||
use PHP_CodeSniffer\Files\File;
|
||||
|
||||
class ValidVariableNameSniff extends AbstractVariableSniff
|
||||
{
|
||||
|
||||
|
||||
/**
|
||||
* Processes class member variables.
|
||||
*
|
||||
* @param File $phpcsFile The file being scanned.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processMemberVar(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// get variable name and properties
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$varTk = $tokens[$stackPtr];
|
||||
$varName = substr($varTk['content'], 1);
|
||||
$varProps = $phpcsFile->getMemberProperties($stackPtr);
|
||||
// check(s)
|
||||
if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName) ) {
|
||||
return;
|
||||
}
|
||||
if ( ! $this->checkVisibilityPrefix($phpcsFile, $stackPtr, $varName, $varProps)) {
|
||||
return;
|
||||
}
|
||||
if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
}//end processMemberVar()
|
||||
|
||||
|
||||
/**
|
||||
* Processes normal variables.
|
||||
*
|
||||
* @param File $phpcsFile The file where this token was found.
|
||||
* @param int $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariable(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
// get variable name
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$varTk = $tokens[$stackPtr];
|
||||
$varName = substr($varTk['content'], 1);
|
||||
// skip the current object variable, i.e. $this
|
||||
if (0 === strcmp($varName, 'this')) {
|
||||
return;
|
||||
}
|
||||
// check(s)
|
||||
if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) {
|
||||
return;
|
||||
}
|
||||
if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) {
|
||||
return;
|
||||
}
|
||||
|
||||
}//end processVariable()
|
||||
|
||||
|
||||
/**
|
||||
* Processes variables in double quoted strings.
|
||||
*
|
||||
* @param File $phpcsFile The file where this token was found.
|
||||
* @param int $stackPtr The position where the token was found.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function processVariableInString(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$stringTk = $tokens[$stackPtr];
|
||||
$stringString = $stringTk['content'];
|
||||
$varAt = self::_getVariablePosition($stringString, 0);
|
||||
while (false !== $varAt) {
|
||||
// get variable name
|
||||
$matches = array();
|
||||
preg_match('/^\$\{?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}?/', substr($stringString, $varAt), $matches);
|
||||
$varName = $matches[1];
|
||||
// check(s)
|
||||
if ( ! $this->checkLowerCase($phpcsFile, $stackPtr, $varName)) {
|
||||
return;
|
||||
}
|
||||
if ( ! $this->checkLength($phpcsFile, $stackPtr, $varName)) {
|
||||
return;
|
||||
}
|
||||
// prepare checking next variable
|
||||
$varAt = self::_getVariablePosition($stringString, $varAt + 1);
|
||||
}
|
||||
|
||||
}//end processVariableInString()
|
||||
|
||||
|
||||
/**
|
||||
* Checks that the variable name is all in lower case, else it add an error
|
||||
* to $phpcsFile. Returns true if variable name is all in lower case, false
|
||||
* otherwise.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $varName The name of the variable to
|
||||
* procced without $, { nor }.
|
||||
*
|
||||
* @return bool true if variable name is all in lower case, false otherwise.
|
||||
*/
|
||||
protected function checkLowerCase(File $phpcsFile, $stackPtr, $varName)
|
||||
{
|
||||
$isInLowerCase = true;
|
||||
if (0 !== strcmp($varName, strtolower($varName))) {
|
||||
// get the expected variable name
|
||||
$varNameWithUnderscores = preg_replace('/([A-Z])/', '_${1}', $varName);
|
||||
$expectedVarName = strtolower(ltrim($varNameWithUnderscores, '_'));
|
||||
// adapts the error message to the error case
|
||||
if (strlen($varNameWithUnderscores) > strlen($varName)) {
|
||||
$error = 'Variables should not use CamelCasing or start with a Capital.';
|
||||
} else {
|
||||
$error = 'Variables should be entirely lowercased.';
|
||||
}
|
||||
$error = $error . 'Please consider "' . $expectedVarName
|
||||
. '" instead of "' . $varName . '".';
|
||||
// adds the error and changes return value
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
$isInLowerCase = false;
|
||||
}
|
||||
return $isInLowerCase;
|
||||
}//end checkLowerCase()
|
||||
|
||||
/**
|
||||
* Checks that an underscore is used at the beginning of a variable only if
|
||||
* it is about a private variable. If it isn't a private variable, then it
|
||||
* must not be prefixed with an underscore. Returns true if $varName is
|
||||
* properly prefixed according to the variable visibility provided in
|
||||
* $varProps, false otherwise.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $varName The name of the variable to
|
||||
* procced without $, { nor }.
|
||||
* @param array $varProps Member variable properties like
|
||||
* its visibility.
|
||||
*
|
||||
* @return bool true if variable name is prefixed with an underscore only
|
||||
* when it is about a private variable, false otherwise.
|
||||
*/
|
||||
protected function checkVisibilityPrefix(File $phpcsFile, $stackPtr, $varName, $varProps)
|
||||
{
|
||||
$isVisibilityPrefixRight = true;
|
||||
$scope = $varProps['scope'];
|
||||
// If it's a private variable, it must have an underscore on the front.
|
||||
if ($scope === 'private' && $varName{0} !== '_') {
|
||||
$error = "Private variable name \"$varName\" must be prefixed with an underscore";
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
$isVisibilityPrefixRight = false;
|
||||
} else if ($scope !== 'private' && $varName{0} === '_') {
|
||||
// If it's not a private variable,
|
||||
// then it must not start with an underscore.
|
||||
if (isset ($scopeSpecified) && true === $scopeSpecified) {
|
||||
$error = "Public variable name \"$varName\" must not be prefixed with an underscore";
|
||||
} else {
|
||||
$error = ucfirst($scope) . " variable name \"$varName\" must not be prefixed with an underscore";
|
||||
}
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
$isVisibilityPrefixRight = false;
|
||||
}
|
||||
return $isVisibilityPrefixRight;
|
||||
}//end checkVisibilityPrefix()
|
||||
|
||||
/**
|
||||
* Checks that variable name length is not too short. Returns true, if it
|
||||
* meets minimum length requirement, false otherwise.
|
||||
*
|
||||
* A variable name is too short if it is shorter than the minimal
|
||||
* length and it isn't in the list of allowed short names nor declared in a
|
||||
* for loop (in which it would be nested).
|
||||
* The minimal length is defined in the function. It is 3 chars now.
|
||||
* The list of allowed short names is defined in the function.
|
||||
* It is case-sensitive. It contains only 'ci' now.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $varName The name of the variable to
|
||||
* procced without $, { nor }.
|
||||
*
|
||||
* @return bool false if variable name $varName is shorter than the minimal
|
||||
* length and it isn't in the list of allowed short names nor declared in a
|
||||
* for loop (in which it would be nested), otherwise true.
|
||||
*/
|
||||
protected function checkLength(File $phpcsFile, $stackPtr, $varName)
|
||||
{
|
||||
$minLength = 3;
|
||||
$allowedShortName = array('ci');
|
||||
|
||||
$isLengthRight = true;
|
||||
// cleans variable name
|
||||
$varName = ltrim($varName, '_');
|
||||
if (strlen($varName) <= $minLength) {
|
||||
// skips adding an error, if it is a specific variable name
|
||||
if (in_array($varName, $allowedShortName)) {
|
||||
return $isLengthRight;
|
||||
}
|
||||
// skips adding an error, if the variable is in a for loop
|
||||
if (false !== self::_isInForLoop($phpcsFile, $stackPtr, $varName)) {
|
||||
return $isLengthRight;
|
||||
}
|
||||
// adds the error message finally
|
||||
$error = 'Very short'
|
||||
. (
|
||||
$minLength > 0 ?
|
||||
' (i.e. less than ' . ($minLength + 1) . ' chars)'
|
||||
: ''
|
||||
)
|
||||
. ', non-word variables like "' . $varName
|
||||
. '" should only be used as iterators in for() loops.';
|
||||
$phpcsFile->addError($error, $stackPtr);
|
||||
$isLengthRight = false;
|
||||
}
|
||||
return $isLengthRight;
|
||||
}//end checkLength()
|
||||
|
||||
/**
|
||||
* Returns the position of closest previous T_FOR, if token associated with
|
||||
* $stackPtr in $phpcsFile is in a for loop, otherwise false.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $varName The name of the variable to
|
||||
* procced without $, { nor }.
|
||||
*
|
||||
* @return int|bool Position of T_FOR if token associated with $stackPtr in
|
||||
* $phpcsFile is in the head of a for loop, otherwise false.
|
||||
*/
|
||||
private static function _isInForLoop(File $phpcsFile, $stackPtr, $varName)
|
||||
{
|
||||
$keepLookingFromPtr = $stackPtr;
|
||||
while (false !== $keepLookingFromPtr) {
|
||||
// looks if it is in (head or body) of a for loop
|
||||
$forPtr = self::_isInForLoopHead($phpcsFile, $keepLookingFromPtr);
|
||||
if (false === $forPtr) {
|
||||
$forPtr = self::_isInForLoopBody($phpcsFile, $keepLookingFromPtr);
|
||||
}
|
||||
// checks if it is declared in here and prepares next step
|
||||
if (false !== $forPtr) {
|
||||
if (false !== self::_isDeclaredInForLoop($phpcsFile, $forPtr, $varName)) {
|
||||
return $forPtr;
|
||||
}
|
||||
$keepLookingFromPtr = $forPtr;
|
||||
} else {
|
||||
$keepLookingFromPtr = false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}//end _isInForLoop()
|
||||
|
||||
/**
|
||||
* Returns the position of closest previous T_FOR, if token associated with
|
||||
* $stackPtr in $phpcsFile is in the head of a for loop, otherwise false.
|
||||
* The head is the code placed between parenthesis next to the key word
|
||||
* 'for' : for (<loop_head>) {<loop_body>}.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return int|bool Position of T_FOR if token associated with $stackPtr in
|
||||
* $phpcsFile is in the head of a for loop, otherwise false.
|
||||
*/
|
||||
private static function _isInForLoopHead(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$isInForLoop = false;
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$currentTk = $tokens[$stackPtr];
|
||||
if (array_key_exists('nested_parenthesis', $currentTk)) {
|
||||
$nestedParenthesis = $currentTk['nested_parenthesis'];
|
||||
foreach ( $nestedParenthesis as $openParPtr => $closeParPtr) {
|
||||
$nonWhitspacePtr = $phpcsFile->findPrevious(
|
||||
array(T_WHITESPACE),
|
||||
$openParPtr - 1,
|
||||
null,
|
||||
true,
|
||||
null,
|
||||
true
|
||||
);
|
||||
if (false !== $nonWhitspacePtr) {
|
||||
$isFor = T_FOR === $tokens[$nonWhitspacePtr]['code'];
|
||||
if ($isFor) {
|
||||
$isInForLoop = $nonWhitspacePtr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $isInForLoop;
|
||||
}//end _isInForLoopHead()
|
||||
|
||||
/**
|
||||
* Returns the position of closest previous T_FOR, if token associated with
|
||||
* $stackPtr in $phpcsFile is in the body of a for loop, otherwise false.
|
||||
* The body are the instructions placed after parenthesis of a 'for'
|
||||
* declaration, enclosed with curly brackets usually.
|
||||
* 'for' : for (<loop_head>) {<loop_body>}.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $stackPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return int|bool Position of T_FOR if token associated with $stackPtr in
|
||||
* $phpcsFile is in the body of a for loop, otherwise false.
|
||||
*/
|
||||
private static function _isInForLoopBody(File $phpcsFile, $stackPtr)
|
||||
{
|
||||
$isInForLoop = false;
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
// get englobing hierarchy
|
||||
$parentPtrAndCode = $tokens[$stackPtr]['conditions'];
|
||||
krsort($parentPtrAndCode);
|
||||
|
||||
// looks for a for loop having a body not enclosed with curly brackets,
|
||||
// which involves that its body contains only one instruction.
|
||||
if (is_array($parentPtrAndCode) && ! empty($parentPtrAndCode)) {
|
||||
$parentCode = reset($parentPtrAndCode);
|
||||
$parentPtr = key($parentPtrAndCode);
|
||||
$openBracketPtr = $tokens[$parentPtr]['scope_opener'];
|
||||
} else {
|
||||
$parentCode = 0;
|
||||
$parentPtr = 0;
|
||||
$openBracketPtr = 0;
|
||||
}
|
||||
$openResearchScopePtr = $stackPtr;
|
||||
// recursive search, since a for statement may englobe other inline
|
||||
// control statement or may be near to function calls, etc...
|
||||
while (false !== $openResearchScopePtr) {
|
||||
$closeParPtr = $phpcsFile->findPrevious(
|
||||
array(T_CLOSE_PARENTHESIS),
|
||||
$openResearchScopePtr,
|
||||
null,
|
||||
false,
|
||||
null,
|
||||
true
|
||||
);
|
||||
// is there a closing parenthesis with a control statement before
|
||||
// the previous instruction ?
|
||||
if (false !== $closeParPtr) {
|
||||
// is there no opening curly bracket specific to
|
||||
// set of instructions, between the closing parenthesis
|
||||
// and the current token ?
|
||||
if ($openBracketPtr < $closeParPtr) {
|
||||
// starts the search from the token before the closing
|
||||
// parenthesis, if it isn't a for statement
|
||||
$openResearchScopePtr = $closeParPtr - 1;
|
||||
// is this parenthesis associated with a for statement ?
|
||||
$closeParenthesisTk = $tokens[$closeParPtr];
|
||||
if (array_key_exists('parenthesis_owner', $closeParenthesisTk)) {
|
||||
$mayBeForPtr = $closeParenthesisTk['parenthesis_owner'];
|
||||
$mayBeForTk = $tokens[$mayBeForPtr];
|
||||
if (T_FOR === $mayBeForTk['code']) {
|
||||
return $mayBeForPtr;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// if it is about a for loop, don't go further
|
||||
// and detect it after one more loop execution, do it now
|
||||
if (T_FOR === $parentCode) {
|
||||
return $parentPtr;
|
||||
}
|
||||
// starts the search from the token before the one
|
||||
// englobing the current statement
|
||||
$openResearchScopePtr = $parentPtr - 1;
|
||||
// re-initialize variables about the englobing structure
|
||||
if (is_array($parentPtrAndCode)) {
|
||||
$parentCode = next($parentPtrAndCode);
|
||||
$parentPtr = key($parentPtrAndCode);
|
||||
$openBracketPtr = $tokens[$parentPtr]['scope_opener'];
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$openResearchScopePtr = false;
|
||||
}
|
||||
}
|
||||
// looks for a for loop having a body enclosed with curly brackets
|
||||
foreach ($parentPtrAndCode as $parentPtr => $parentCode) {
|
||||
if (T_FOR === $parentCode) {
|
||||
return $parentPtr;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}//end _isInForLoopBody()
|
||||
|
||||
/**
|
||||
* Returns true if a variable declared in the head of the for loop pointed
|
||||
* by $forPtr in file $phpcsFile has the name $varName.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $forPtr The position of the 'for' token
|
||||
* in the stack passed in $tokens.
|
||||
* @param string $varName The name of the variable to
|
||||
* procced without $, { nor }.
|
||||
*
|
||||
* @return int|bool true if a variable declared in the head of the for loop
|
||||
* pointed by $forPtr in file $phpcsFile has the name $varName.
|
||||
*/
|
||||
private static function _isDeclaredInForLoop(File $phpcsFile, $forPtr, $varName)
|
||||
{
|
||||
$isDeclaredInFor = false;
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$forVarPtrs = self::_getVarDeclaredInFor($phpcsFile, $forPtr);
|
||||
foreach ($forVarPtrs as $forVarPtr) {
|
||||
$forVarTk = $tokens[$forVarPtr];
|
||||
// get variable name
|
||||
$matches = array();
|
||||
preg_match('/^\$\{?([a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*)\}?/', $forVarTk['content'], $matches);
|
||||
$forVarName = $matches[1];
|
||||
if (0 === strcmp($forVarName, $varName)) {
|
||||
$isDeclaredInFor = $forVarPtr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return $isDeclaredInFor;
|
||||
}//end _isDeclaredInForLoop()
|
||||
|
||||
/**
|
||||
* Returns list of pointers to variables declared in for loop associated to
|
||||
* $forPtr in file $phpcsFile.
|
||||
*
|
||||
* All pointers in the result list are pointing to token with code
|
||||
* T_VARIABLE. An exception is raised, if $forPtr doesn't point a token with
|
||||
* code T_FOR.
|
||||
*
|
||||
* @param File $phpcsFile The current file being processed.
|
||||
* @param int $forPtr The position of the current token
|
||||
* in the stack passed in $tokens.
|
||||
*
|
||||
* @return array List of pointers to variables declared in for loop $forPtr.
|
||||
*/
|
||||
private static function _getVarDeclaredInFor(File $phpcsFile, $forPtr)
|
||||
{
|
||||
$tokens = $phpcsFile->getTokens();
|
||||
$forTk = $tokens[$forPtr];
|
||||
if (T_FOR !== $forTk['code']) {
|
||||
throw new PHP_CodeSniffer_Exception('$forPtr must be of type T_FOR');
|
||||
}
|
||||
$openParPtr = $forTk['parenthesis_opener'];
|
||||
$openParenthesisTk = $tokens[$openParPtr];
|
||||
$endOfDeclPtr = $phpcsFile->findNext(array(T_SEMICOLON), $openParPtr);
|
||||
$forVarPtrs = array();
|
||||
$varPtr = $phpcsFile->findNext(
|
||||
array(T_VARIABLE),
|
||||
$openParPtr + 1,
|
||||
$endOfDeclPtr
|
||||
);
|
||||
while (false !== $varPtr) {
|
||||
$forVarPtrs [] = $varPtr;
|
||||
$varPtr = $phpcsFile->findNext(
|
||||
array(T_VARIABLE),
|
||||
$varPtr + 1,
|
||||
$endOfDeclPtr
|
||||
);
|
||||
}
|
||||
return $forVarPtrs;
|
||||
}//end _getVarDeclaredInFor()
|
||||
|
||||
/**
|
||||
* Returns the position of first occurrence of a PHP variable starting with
|
||||
* $ in $haystack from $offset.
|
||||
*
|
||||
* @param string $haystack The string to search in.
|
||||
* @param int $offset The optional offset parameter allows you to
|
||||
* specify which character in haystack to start
|
||||
* searching. The returned position is still
|
||||
* relative to the beginning of haystack.
|
||||
*
|
||||
* @return mixed The position as an integer
|
||||
* or the boolean false, if no variable is found.
|
||||
*/
|
||||
private static function _getVariablePosition($haystack, $offset = 0)
|
||||
{
|
||||
$var_starts_at = strpos($haystack, '$', $offset);
|
||||
$is_a_var = false;
|
||||
while (false !== $var_starts_at && ! $is_a_var) {
|
||||
// makes sure that $ is used for a variable and not as a symbol,
|
||||
// if $ is protected with the escape char, then it is a symbol.
|
||||
if (0 !== strcmp($haystack[$var_starts_at - 1], '\\')) {
|
||||
if (0 === strcmp($haystack[$var_starts_at + 1], '{')) {
|
||||
// there is an opening brace in the right place
|
||||
// so it looks for the closing brace in the right place
|
||||
$hsChunk2 = substr($haystack, $var_starts_at + 2);
|
||||
if (1 === preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*\}/', $hsChunk2)) {
|
||||
$is_a_var = true;
|
||||
}
|
||||
} else {
|
||||
$hsChunk1 = substr($haystack, $var_starts_at + 1);
|
||||
if (1 === preg_match('/^[a-zA-Z_\x7f-\xff]/', $hsChunk1)) {
|
||||
// $ is used for a variable and not as a symbol,
|
||||
// since what follows $ matchs the definition of
|
||||
// a variable label for PHP.
|
||||
$is_a_var = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// update $var_starts_at for the next variable
|
||||
// only if no variable was found, since it is returned otherwise.
|
||||
if ( ! $is_a_var) {
|
||||
$var_starts_at = strpos($haystack, '$', $var_starts_at + 1);
|
||||
}
|
||||
}
|
||||
if ($is_a_var) {
|
||||
return $var_starts_at;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}//end _getVariablePosition()
|
||||
}//end class
|
||||
|
||||
?>
|
@ -1,47 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" ?>
|
||||
<ruleset name="CodeIgniter">
|
||||
<description>CodeIgniter coding standard as described at http://codeigniter.com/user_guide/general/styleguide.html.</description>
|
||||
<rule ref="Generic.Files.LineEndings">
|
||||
<properties>
|
||||
<property name="eolChar" value="\n"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- PHP files should OMIT the closing PHP tag -->
|
||||
<rule ref="Zend.Files.ClosingTag"/>
|
||||
<!-- Always use full PHP opening tags -->
|
||||
<rule ref="Generic.PHP.DisallowShortOpenTag"/>
|
||||
|
||||
<!-- Constants should always be fully uppercase -->
|
||||
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
|
||||
<!-- TRUE, FALSE, and NULL keywords should always be fully uppercase -->
|
||||
<rule ref="Generic.PHP.UpperCaseConstant"/>
|
||||
|
||||
<!-- One statement per line -->
|
||||
<rule ref="Generic.Formatting.DisallowMultipleStatements"/>
|
||||
|
||||
<!-- Classes and functions should be commented -->
|
||||
<rule ref="PEAR.Commenting.ClassComment"/>
|
||||
<rule ref="PEAR.Commenting.FunctionComment"/>
|
||||
<!-- <rule ref="Squiz.Commenting.FunctionCommentThrowTag"/>-->
|
||||
<!-- Use warnings for docblock comments for files and variables, since nothing is cleary explained -->
|
||||
<rule ref="PEAR.Commenting.FileComment">
|
||||
<properties>
|
||||
<property name="error" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
<rule ref="Squiz.Commenting.VariableComment">
|
||||
<properties>
|
||||
<property name="error" value="false"/>
|
||||
</properties>
|
||||
</rule>
|
||||
|
||||
<!-- Use Allman style indenting. With the exception of Class declarations,
|
||||
braces are always placed on a line by themselves, and indented at the same level as the control statement that "owns" them. -->
|
||||
<rule ref="Generic.Functions.OpeningFunctionBraceBsdAllman"/>
|
||||
<rule ref="PEAR.WhiteSpace.ScopeClosingBrace"/>
|
||||
<rule ref="Generic.Functions.FunctionCallArgumentSpacing"/>
|
||||
|
||||
<!-- @todo Please see PHP_CodeSniffer_Standards_CodeIgniter_CodeIgniterCodingStandard for more details about what there is to do -->
|
||||
</ruleset>
|
||||
|
@ -1,9 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" stopOnFailure="false" bootstrap="../tests/bootstrap.php" beStrictAboutTestsThatDoNotTestAnything="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
|
||||
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" colors="true" stopOnFailure="false" bootstrap="../tests/bootstrap.php" beStrictAboutTestsThatDoNotTestAnything="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.1/phpunit.xsd">
|
||||
<coverage>
|
||||
<include>
|
||||
<directory suffix=".php">../src</directory>
|
||||
</include>
|
||||
<report>
|
||||
<clover outputFile="logs/clover.xml"/>
|
||||
<html outputDirectory="../coverage"/>
|
||||
@ -27,4 +24,9 @@
|
||||
<server name="REQUEST_URI" value="/"/>
|
||||
<server name="REQUEST_METHOD" value="GET"/>
|
||||
</php>
|
||||
<source>
|
||||
<include>
|
||||
<directory suffix=".php">../src</directory>
|
||||
</include>
|
||||
</source>
|
||||
</phpunit>
|
||||
|
@ -1,99 +0,0 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
|
||||
$file_patterns = [
|
||||
'app/appConf/*.php',
|
||||
'app/bootstrap.php',
|
||||
'migrations/*.php',
|
||||
'src/**/*.php',
|
||||
'src/*.php',
|
||||
'tests/**/*.php',
|
||||
'tests/*.php',
|
||||
'index.php',
|
||||
'Robofile.php'
|
||||
];
|
||||
|
||||
if ( ! function_exists('glob_recursive'))
|
||||
{
|
||||
// Does not support flag GLOB_BRACE
|
||||
|
||||
function glob_recursive(string $pattern, int $flags = 0): array
|
||||
{
|
||||
$files = glob($pattern, $flags);
|
||||
|
||||
foreach (glob(dirname($pattern) . '/*', GLOB_ONLYDIR | GLOB_NOSORT) as $dir)
|
||||
{
|
||||
$files = array_merge($files, glob_recursive($dir . '/' . basename($pattern), $flags));
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
|
||||
function get_text_to_replace(array $tokens): string
|
||||
{
|
||||
$output = '';
|
||||
|
||||
// Tokens have the follow structure if arrays:
|
||||
// [0] => token type constant
|
||||
// [1] => raw syntax parsed to that token
|
||||
// [2] => line number
|
||||
foreach($tokens as $token)
|
||||
{
|
||||
// Since we only care about opening docblocks,
|
||||
// bail out when we get to the namespace token
|
||||
if (is_array($token) && $token[0] === T_NAMESPACE)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_array($token))
|
||||
{
|
||||
$token = $token[1];
|
||||
}
|
||||
|
||||
$output .= $token;
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
function get_tokens(string $source): array
|
||||
{
|
||||
return token_get_all($source);
|
||||
}
|
||||
|
||||
function replace_files(array $files, string $template): void
|
||||
{
|
||||
print_r($files);
|
||||
foreach ($files as $file)
|
||||
{
|
||||
$source = file_get_contents($file);
|
||||
if ($source === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (stripos($source, 'namespace') === FALSE)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
$tokens = get_tokens($source);
|
||||
$text_to_replace = get_text_to_replace($tokens);
|
||||
|
||||
$header = file_get_contents(__DIR__ . $template);
|
||||
$new_text = "<?php declare(strict_types=1);\n{$header}";
|
||||
|
||||
$new_source = str_replace($text_to_replace, $new_text, $source);
|
||||
file_put_contents($file, $new_source);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($file_patterns as $glob)
|
||||
{
|
||||
$files = glob_recursive($glob);
|
||||
replace_files($files, '/header_comment.txt');
|
||||
}
|
||||
|
||||
echo "Successfully updated headers \n";
|
@ -13,8 +13,8 @@
|
||||
"autoload": {
|
||||
"files": [
|
||||
"src/Ion/functions.php",
|
||||
"src/AnimeClient/constants.php",
|
||||
"src/AnimeClient/AnimeClient.php"
|
||||
"src/AnimeClient.php",
|
||||
"src/AnimeClient/constants.php"
|
||||
],
|
||||
"psr-4": {
|
||||
"Aviat\\": "src/"
|
||||
@ -23,61 +23,46 @@
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Aviat\\AnimeClient\\Tests\\": "tests/AnimeClient",
|
||||
"Aviat\\Ion\\Tests\\": "tests/Ion",
|
||||
"CodeIgniter\\": "build/CodeIgniter/"
|
||||
"Aviat\\Ion\\Tests\\": "tests/Ion"
|
||||
}
|
||||
},
|
||||
"config": {
|
||||
"lock": false,
|
||||
"platform": {
|
||||
"php": "8"
|
||||
}
|
||||
"lock": false
|
||||
},
|
||||
"require": {
|
||||
"amphp/amp": "^2.5.0",
|
||||
"amphp/http-client": "^4.5.0",
|
||||
"amphp/http-client": "^v5.0.0",
|
||||
"aura/html": "^2.5.0",
|
||||
"aura/router": "^3.1.0",
|
||||
"aura/router": "^3.3.0",
|
||||
"aura/session": "^2.1.0",
|
||||
"aviat/banker": "^3.1.1",
|
||||
"aviat/query": "^3.0.0",
|
||||
"danielstjules/stringy": "^3.1.0",
|
||||
"aviat/banker": "^4.1.2",
|
||||
"aviat/query": "^4.1.0",
|
||||
"ext-dom": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-intl": "*",
|
||||
"ext-json": "*",
|
||||
"ext-gd": "*",
|
||||
"ext-mbstring": "*",
|
||||
"ext-pdo": "*",
|
||||
"laminas/laminas-diactoros": "^2.5.0",
|
||||
"laminas/laminas-httphandlerrunner": "^1.1.0",
|
||||
"laminas/laminas-diactoros": "^3.0.0",
|
||||
"laminas/laminas-httphandlerrunner": "^2.6.1",
|
||||
"maximebf/consolekit": "^1.0.3",
|
||||
"monolog/monolog": "^2.0.2",
|
||||
"php": ">= 8.0.0",
|
||||
"psr/container": "^1.0.0",
|
||||
"psr/http-message": "^1.0.1",
|
||||
"psr/log": "^1.1.3",
|
||||
"robmorgan/phinx": "^0.12.4",
|
||||
"monolog/monolog": "^3.0.0",
|
||||
"php": ">= 8.2.0",
|
||||
"psr/http-message": "^1.0.1 || ^2.0.0",
|
||||
"symfony/polyfill-mbstring": "^1.0.0",
|
||||
"symfony/polyfill-util": "^1.0.0",
|
||||
"tracy/tracy": "^2.8.0",
|
||||
"yosymfony/toml": "^1.0.4"
|
||||
},
|
||||
"require-dev": {
|
||||
"pdepend/pdepend": "^2.",
|
||||
"phploc/phploc": "^7.0.0",
|
||||
"phpmd/phpmd": "^2.8.2",
|
||||
"phpstan/phpstan": "^0.12.19",
|
||||
"phpunit/phpunit": "^9.5.0",
|
||||
"phpstan/phpstan": "^1.2.0",
|
||||
"phpunit/phpunit": "^10.0.0",
|
||||
"roave/security-advisories": "dev-master",
|
||||
"sebastian/phpcpd": "^6.0.0",
|
||||
"spatie/phpunit-snapshot-assertions": "^4.1.0",
|
||||
"squizlabs/php_codesniffer": "^3.5.4"
|
||||
"spatie/phpunit-snapshot-assertions": "^5.0.1"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "vendor/bin/robo build",
|
||||
"build:css": "cd public && npm run build:css && cd ..",
|
||||
"build:js": "cd public && npm run build:js && cd ..",
|
||||
"clean": "vendor/bin/robo clean",
|
||||
"coverage": "phpdbg -qrr -- vendor/bin/phpunit -c build",
|
||||
"coverage": "php -dpcov.enabled=1 -dpcov.directory=. -dpcov.exclude=\"~vendor~\" ./vendor/bin/phpunit -c build",
|
||||
"phpstan": "phpstan analyse -c phpstan.neon",
|
||||
"watch:css": "cd public && npm run watch:css",
|
||||
"watch:js": "cd public && npm run watch:js",
|
||||
@ -85,9 +70,7 @@
|
||||
"test-update": "vendor/bin/phpunit -c build --no-coverage -d --update-snapshots"
|
||||
},
|
||||
"scripts-descriptions": {
|
||||
"build": "Generate the api docs",
|
||||
"build:css": "Generate browser css",
|
||||
"clean": "Remove documentation generation files and folders",
|
||||
"coverage": "Generate a test coverage report",
|
||||
"phpstan": "Run PHP Static analysis",
|
||||
"test": "Run the unit tests"
|
||||
|
6
console
6
console
@ -9,8 +9,8 @@ use ConsoleKit\Console;
|
||||
|
||||
$GLOBALS['_SERVER']['HTTP_HOST'] = 'localhost';
|
||||
|
||||
define('APP_DIR', __DIR__ . '/app');
|
||||
define('TEMPLATE_DIR', APP_DIR . '/templates');
|
||||
const APP_DIR = __DIR__ . '/app';
|
||||
const TEMPLATE_DIR = APP_DIR . '/templates';
|
||||
|
||||
// -----------------------------------------------------------------------------
|
||||
// Start console script
|
||||
@ -26,7 +26,7 @@ try
|
||||
'sync:lists' => Command\SyncLists::class
|
||||
]))->run();
|
||||
}
|
||||
catch (\Throwable)
|
||||
catch (Throwable)
|
||||
{
|
||||
|
||||
}
|
||||
|
@ -333,7 +333,8 @@ td.danger, td.danger:hover, td.danger:active {
|
||||
.borderless th,
|
||||
.invisible tr,
|
||||
.invisible td,
|
||||
.invisible th {
|
||||
.invisible th,
|
||||
table.invisible {
|
||||
box-shadow: none;
|
||||
border: 0;
|
||||
}
|
||||
@ -628,6 +629,14 @@ picture.cover {
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
/* There are two .name elements, just darken them both in this case! */
|
||||
.media.search.disabled .name {
|
||||
background-color: #000;
|
||||
background-color: rgba(0, 0, 0, 0.75);
|
||||
background-size: cover;
|
||||
background-size: contain;
|
||||
background-repeat: no-repeat;
|
||||
}
|
||||
|
||||
.media.search > .row {
|
||||
z-index: 6;
|
||||
@ -828,19 +837,11 @@ aside.info {
|
||||
max-width: 390px;
|
||||
}
|
||||
|
||||
/* .fixed aside.info + article {
|
||||
max-width: inherit;
|
||||
} */
|
||||
|
||||
aside picture, aside img {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
/* aside.info + article {
|
||||
max-width: 66%;
|
||||
} */
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
User page styles
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
@ -1,7 +1,8 @@
|
||||
import _ from './anime-client.js'
|
||||
import { renderAnimeSearchResults } from './template-helpers.js'
|
||||
import { renderSearchResults } from './template-helpers.js'
|
||||
import { getNestedProperty, hasNestedProperty } from "./fns";
|
||||
|
||||
const search = (query) => {
|
||||
const search = (query, isCollection = false) => {
|
||||
// Show the loader
|
||||
_.show('.cssload-loader');
|
||||
|
||||
@ -13,10 +14,11 @@ const search = (query) => {
|
||||
_.hide('.cssload-loader');
|
||||
|
||||
// Show the results
|
||||
_.$('#series-list')[ 0 ].innerHTML = renderAnimeSearchResults(searchResults);
|
||||
_.$('#series-list')[ 0 ].innerHTML = renderSearchResults('anime', searchResults, isCollection);
|
||||
});
|
||||
};
|
||||
|
||||
// Anime list search
|
||||
if (_.hasElement('.anime #search')) {
|
||||
let prevRequest = null;
|
||||
|
||||
@ -34,6 +36,24 @@ if (_.hasElement('.anime #search')) {
|
||||
}));
|
||||
}
|
||||
|
||||
// Anime collection search
|
||||
if (_.hasElement('#search-anime-collection')) {
|
||||
let prevRequest = null;
|
||||
|
||||
_.on('#search-anime-collection', 'input', _.throttle(250, (e) => {
|
||||
const query = encodeURIComponent(e.target.value);
|
||||
if (query === '') {
|
||||
return;
|
||||
}
|
||||
|
||||
if (prevRequest !== null) {
|
||||
prevRequest.abort();
|
||||
}
|
||||
|
||||
prevRequest = search(query, true);
|
||||
}));
|
||||
}
|
||||
|
||||
// Action to increment episode count
|
||||
_.on('body.anime.list', 'click', '.plus-one', (e) => {
|
||||
let parentSel = _.closestParent(e.target, 'article');
|
||||
@ -44,12 +64,21 @@ _.on('body.anime.list', 'click', '.plus-one', (e) => {
|
||||
// Setup the update data
|
||||
let data = {
|
||||
id: parentSel.dataset.kitsuId,
|
||||
anilist_id: parentSel.dataset.anilistId,
|
||||
mal_id: parentSel.dataset.malId,
|
||||
data: {
|
||||
progress: watchedCount + 1
|
||||
}
|
||||
};
|
||||
|
||||
const displayMessage = (type, message) => {
|
||||
_.hide('#loading-shadow');
|
||||
_.showMessage(type, `${message} ${title}`);
|
||||
_.scrollToTop();
|
||||
}
|
||||
|
||||
const showError = () => displayMessage('error', 'Failed to update');
|
||||
|
||||
// If the episode count is 0, and incremented,
|
||||
// change status to currently watching
|
||||
if (isNaN(watchedCount) || watchedCount === 0) {
|
||||
@ -69,29 +98,31 @@ _.on('body.anime.list', 'click', '.plus-one', (e) => {
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
success: (res) => {
|
||||
try {
|
||||
const resData = JSON.parse(res);
|
||||
|
||||
if (resData.error) {
|
||||
_.hide('#loading-shadow');
|
||||
_.showMessage('error', `Failed to update ${title}. `);
|
||||
_.scrollToTop();
|
||||
// Do a rough sanity check for weird errors
|
||||
let updatedProgress = getNestedProperty(resData, 'data.libraryEntry.update.libraryEntry.progress');
|
||||
if (hasNestedProperty(resData, 'error') || updatedProgress !== data.data.progress) {
|
||||
showError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (resData.data.libraryEntry.update.libraryEntry.status === 'COMPLETED') {
|
||||
// We've completed the series
|
||||
if (getNestedProperty(resData, 'data.libraryEntry.update.libraryEntry.status') === 'COMPLETED') {
|
||||
_.hide(parentSel);
|
||||
displayMessage('success', 'Completed')
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_.hide('#loading-shadow');
|
||||
|
||||
_.showMessage('success', `Successfully updated ${title}`);
|
||||
// Just a normal update
|
||||
_.$('.completed_number', parentSel)[ 0 ].textContent = ++watchedCount;
|
||||
_.scrollToTop();
|
||||
},
|
||||
error: () => {
|
||||
_.hide('#loading-shadow');
|
||||
_.showMessage('error', `Failed to update ${title}. `);
|
||||
_.scrollToTop();
|
||||
displayMessage('success', 'Updated');
|
||||
} catch (_) {
|
||||
showError();
|
||||
}
|
||||
},
|
||||
error: showError,
|
||||
});
|
||||
});
|
@ -6,9 +6,22 @@ const LightTableSorter = (() => {
|
||||
const sort = (a, b) => {
|
||||
let textA = text(a);
|
||||
let textB = text(b);
|
||||
const n = parseInt(textA, 10);
|
||||
if (n) {
|
||||
textA = n;
|
||||
console.log("Comparing " + textA + " and " + textB)
|
||||
|
||||
if(th.classList.contains("numeric")){
|
||||
let arrayA = textA.replace('episodes: ','').replace('-',0).split("/");
|
||||
let arrayB = textB.replace('episodes: ','').replace('-',0).split("/");
|
||||
if(arrayA.length > 1) {
|
||||
textA = parseInt(arrayA[0],10) / parseInt(arrayA[1],10);
|
||||
textB = parseInt(arrayB[0],10) / parseInt(arrayB[1],10);
|
||||
}
|
||||
else{
|
||||
textA = parseInt(arrayA[0],10);
|
||||
textB = parseInt(arrayB[0],10);
|
||||
}
|
||||
}
|
||||
else if (parseInt(textA, 10)) {
|
||||
textA = parseInt(textA, 10);
|
||||
textB = parseInt(textB, 10);
|
||||
}
|
||||
if (textA > textB) {
|
||||
@ -59,6 +72,7 @@ const LightTableSorter = (() => {
|
||||
for (let i = 0, len = ths.length; i < len; i++) {
|
||||
let th = ths[i];
|
||||
th.classList.add('sorting');
|
||||
th.classList.add('testing');
|
||||
results.push(th.onclick = onClickEvent);
|
||||
}
|
||||
return results;
|
||||
|
103
frontEndSrc/js/fns.js
Normal file
103
frontEndSrc/js/fns.js
Normal file
@ -0,0 +1,103 @@
|
||||
/**
|
||||
* Make sure properties are in an easily splittable format
|
||||
*
|
||||
* @private
|
||||
* @param {String} props
|
||||
* @param {String} [sep='.'] The default separator
|
||||
* @return {String}
|
||||
*/
|
||||
function _normalizeProperty(props, sep = '.') {
|
||||
// Since we split by period, and property lookup
|
||||
// is the same by dot or [], replace bracket lookups
|
||||
// with periods
|
||||
return props.replace(/\[(.*?)]/g, sep + '$1');
|
||||
}
|
||||
|
||||
/**
|
||||
* Tell if a nested object has a given property (or array a given index)
|
||||
* given an object such as a.b.c.d = 5, hasNestedProperty(a, 'b.c.d') will return true.
|
||||
*
|
||||
* @param {Object} object the object to get the property from
|
||||
* @param {String} property the path to the property as a string
|
||||
* @returns {boolean} true when property in object, false otherwise
|
||||
*/
|
||||
export function hasNestedProperty(object, property) {
|
||||
if (object && typeof object === 'object') {
|
||||
if (typeof property === 'string' && property !== '') {
|
||||
property = _normalizeProperty(property);
|
||||
|
||||
let split = property.split('.');
|
||||
return split.reduce((obj, prop, idx, array) => {
|
||||
if (idx === array.length - 1) {
|
||||
return !!(obj && obj.hasOwnProperty(prop));
|
||||
}
|
||||
|
||||
return obj && obj[prop];
|
||||
}, object);
|
||||
} else if (typeof property === 'number') {
|
||||
return property in object;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of a deeply nested property in an object
|
||||
*
|
||||
* @param {Object} object the object to get the property
|
||||
* @param {string} property the path to the property as a string
|
||||
* @param {string} [sep='.'] The default separator to split on
|
||||
* @return {*} the value of the property
|
||||
*/
|
||||
export function getNestedProperty(object, property, sep = '.') {
|
||||
if (isType('string', property) && property !== '') {
|
||||
// convert numbers to dot syntax
|
||||
property = _normalizeProperty(property, sep);
|
||||
const levels = property.split(sep);
|
||||
|
||||
try {
|
||||
return levels.reduce((obj, prop) => obj[prop], object);
|
||||
} catch (e) {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reliably get the type of the value of a variable
|
||||
*
|
||||
* @param {*} x The variable to get the type of
|
||||
* @return {string} The name of the type
|
||||
*/
|
||||
export function getType(x) {
|
||||
// is it an array?
|
||||
if (Array.isArray(x)) {
|
||||
return 'array';
|
||||
}
|
||||
|
||||
// Use typeof for truthy primitives
|
||||
if (typeof x !== 'object') {
|
||||
return (typeof x).toLowerCase();
|
||||
}
|
||||
|
||||
const type = function () {
|
||||
return Object.prototype.toString.call(this).slice(8, -1);
|
||||
}
|
||||
|
||||
// Otherwise, strip the type out of the '[Object x]' toString value
|
||||
return type.call(x).toLowerCase();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the value matches the passed type name
|
||||
*
|
||||
* @param {string} type Javascript type name
|
||||
* @param {*} val The value to type check
|
||||
* @return {boolean}
|
||||
*/
|
||||
export function isType(type, val) {
|
||||
return getType(val) === String(type).toLowerCase();
|
||||
}
|
@ -1,12 +1,13 @@
|
||||
import _ from './anime-client.js'
|
||||
import { renderMangaSearchResults } from './template-helpers.js'
|
||||
import { renderSearchResults } from './template-helpers.js'
|
||||
import { getNestedProperty, hasNestedProperty } from "./fns";
|
||||
|
||||
const search = (query) => {
|
||||
_.show('.cssload-loader');
|
||||
return _.get(_.url('/manga/search'), { query }, (searchResults, status) => {
|
||||
searchResults = JSON.parse(searchResults);
|
||||
_.hide('.cssload-loader');
|
||||
_.$('#series-list')[ 0 ].innerHTML = renderMangaSearchResults(searchResults);
|
||||
_.$('#series-list')[ 0 ].innerHTML = renderSearchResults('manga', searchResults);
|
||||
});
|
||||
};
|
||||
|
||||
@ -36,7 +37,7 @@ _.on('.manga.list', 'click', '.edit-buttons button', (e) => {
|
||||
let type = thisSel.classList.contains('plus-one-chapter') ? 'chapter' : 'volume';
|
||||
let completed = parseInt(_.$(`.${type}s_read`, parentSel)[ 0 ].textContent, 10) || 0;
|
||||
let total = parseInt(_.$(`.${type}_count`, parentSel)[ 0 ].textContent, 10);
|
||||
let mangaName = _.$('.name', parentSel)[ 0 ].textContent;
|
||||
let title = _.$('.name', parentSel)[ 0 ].textContent;
|
||||
|
||||
if (isNaN(completed)) {
|
||||
completed = 0;
|
||||
@ -45,12 +46,21 @@ _.on('.manga.list', 'click', '.edit-buttons button', (e) => {
|
||||
// Setup the update data
|
||||
let data = {
|
||||
id: parentSel.dataset.kitsuId,
|
||||
anilist_id: parentSel.dataset.anilistId,
|
||||
mal_id: parentSel.dataset.malId,
|
||||
data: {
|
||||
progress: completed
|
||||
}
|
||||
};
|
||||
|
||||
const displayMessage = (type, message) => {
|
||||
_.hide('#loading-shadow');
|
||||
_.showMessage(type, `${message} ${title}`);
|
||||
_.scrollToTop();
|
||||
}
|
||||
|
||||
const showError = () => displayMessage('error', 'Failed to update');
|
||||
|
||||
// If the episode count is 0, and incremented,
|
||||
// change status to currently reading
|
||||
if (isNaN(completed) || completed === 0) {
|
||||
@ -73,28 +83,32 @@ _.on('.manga.list', 'click', '.edit-buttons button', (e) => {
|
||||
type: 'POST',
|
||||
mimeType: 'application/json',
|
||||
success: (res) => {
|
||||
const resData = JSON.parse(res)
|
||||
if (resData.error) {
|
||||
_.hide('#loading-shadow');
|
||||
_.showMessage('error', `Failed to update ${mangaName}. `);
|
||||
_.scrollToTop();
|
||||
try {
|
||||
const resData = JSON.parse(res);
|
||||
|
||||
// Do a rough sanity check for weird errors
|
||||
let updatedProgress = getNestedProperty(resData, 'data.libraryEntry.update.libraryEntry.progress');
|
||||
if (hasNestedProperty(resData, 'error') || updatedProgress !== data.data.progress) {
|
||||
showError();
|
||||
return;
|
||||
}
|
||||
|
||||
if (String(data.data.status).toUpperCase() === 'COMPLETED') {
|
||||
// We've completed the series
|
||||
if (getNestedProperty(resData, 'data.libraryEntry.update.libraryEntry.status') === 'COMPLETED') {
|
||||
_.hide(parentSel);
|
||||
displayMessage('success', 'Completed')
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
_.hide('#loading-shadow');
|
||||
|
||||
// Just a normal update
|
||||
_.$(`.${type}s_read`, parentSel)[ 0 ].textContent = String(completed);
|
||||
_.showMessage('success', `Successfully updated ${mangaName}`);
|
||||
_.scrollToTop();
|
||||
},
|
||||
error: () => {
|
||||
_.hide('#loading-shadow');
|
||||
_.showMessage('error', `Failed to update ${mangaName}`);
|
||||
_.scrollToTop();
|
||||
displayMessage('success', 'Updated');
|
||||
|
||||
} catch (_) {
|
||||
showError();
|
||||
}
|
||||
},
|
||||
error: showError,
|
||||
});
|
||||
});
|
@ -5,23 +5,62 @@ import _ from './anime-client.js';
|
||||
_.on('main', 'change', '.big-check', (e) => {
|
||||
const id = e.target.id;
|
||||
document.getElementById(`mal_${id}`).checked = true;
|
||||
document.getElementById(`anilist_${id}`).checked = true;
|
||||
});
|
||||
|
||||
export function renderAnimeSearchResults (data) {
|
||||
return data.map(item => {
|
||||
const titles = item.titles.join('<br />');
|
||||
/**
|
||||
* On search results with an existing library entry, this shows that fact, with an edit link for the existing
|
||||
* library entry
|
||||
*
|
||||
* @param {'anime'|'manga'} type
|
||||
* @param {Object} item
|
||||
* @param isCollection
|
||||
* @returns {String}
|
||||
*/
|
||||
function renderEditLink (type, item, isCollection = false) {
|
||||
if (isCollection || item.libraryEntry === null) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return `
|
||||
<article class="media search">
|
||||
<div class="row">
|
||||
<span class="edit"><big>[ Already in List ]</big></span>
|
||||
</div>
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed" href="/${type}/edit/${item.libraryEntry.id}/${item.libraryEntry.status}">Edit</a>
|
||||
</span>
|
||||
</div>
|
||||
<div class="row"><span class="edit"> </span></div>
|
||||
`
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the search results for a media item
|
||||
*
|
||||
* @param {'anime'|'manga'} type
|
||||
* @param {Object} data
|
||||
* @param {boolean} isCollection
|
||||
* @returns {String}
|
||||
*/
|
||||
export function renderSearchResults (type, data, isCollection = false) {
|
||||
return data.map(item => {
|
||||
const titles = item.titles.join('<br />');
|
||||
let disabled = item.libraryEntry !== null ? 'disabled' : '';
|
||||
const editLink = renderEditLink(type, item, isCollection);
|
||||
|
||||
if (isCollection) {
|
||||
disabled = '';
|
||||
}
|
||||
|
||||
return `
|
||||
<article class="media search ${disabled}">
|
||||
<div class="name">
|
||||
<input type="radio" class="mal-check" id="mal_${item.slug}" name="mal_id" value="${item.mal_id}" />
|
||||
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${item.id}" />
|
||||
<input type="radio" class="mal-check" id="anilist_${item.slug}" name="anilist_id" value="${item.anilist_id}" ${disabled} />
|
||||
<input type="radio" class="mal-check" id="mal_${item.slug}" name="mal_id" value="${item.mal_id}" ${disabled} />
|
||||
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${item.id}" ${disabled} />
|
||||
<label for="${item.slug}">
|
||||
<picture width="220">
|
||||
<source srcset="/public/images/anime/${item.id}.webp" type="image/webp" />
|
||||
<source srcset="/public/images/anime/${item.id}.jpg" type="image/jpeg" />
|
||||
<img src="/public/images/anime/${item.id}.jpg" alt="" width="220" />
|
||||
</picture>
|
||||
<img src="${item.coverImage}" alt="" width="220" />
|
||||
<span class="name">
|
||||
${item.canonicalTitle}<br />
|
||||
<small>${titles}</small>
|
||||
@ -29,41 +68,10 @@ export function renderAnimeSearchResults (data) {
|
||||
</label>
|
||||
</div>
|
||||
<div class="table">
|
||||
${editLink}
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed" href="/anime/details/${item.slug}">Info Page</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</article>
|
||||
`;
|
||||
}).join('');
|
||||
}
|
||||
|
||||
export function renderMangaSearchResults (data) {
|
||||
return data.map(item => {
|
||||
const titles = item.titles.join('<br />');
|
||||
return `
|
||||
<article class="media search">
|
||||
<div class="name">
|
||||
<input type="radio" id="mal_${item.slug}" name="mal_id" value="${item.mal_id}" />
|
||||
<input type="radio" class="big-check" id="${item.slug}" name="id" value="${item.id}" />
|
||||
<label for="${item.slug}">
|
||||
<picture width="220">
|
||||
<source srcset="/public/images/manga/${item.id}.webp" type="image/webp" />
|
||||
<source srcset="/public/images/manga/${item.id}.jpg" type="image/jpeg" />
|
||||
<img src="/public/images/manga/${item.id}.jpg" alt="" width="220" />
|
||||
</picture>
|
||||
<span class="name">
|
||||
${item.canonicalTitle}<br />
|
||||
<small>${titles}</small>
|
||||
</span>
|
||||
</label>
|
||||
</div>
|
||||
<div class="table">
|
||||
<div class="row">
|
||||
<span class="edit">
|
||||
<a class="bracketed" href="/manga/details/${item.slug}">Info Page</a>
|
||||
<a class="bracketed" href="/${type}/details/${item.slug}">Info Page</a>
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -11,11 +11,11 @@
|
||||
"devDependencies": {
|
||||
"@swc/cli": "^0.1.39",
|
||||
"@swc/core": "^1.2.54",
|
||||
"concurrently": "^6.0.2",
|
||||
"cssnano": "^5.0.1",
|
||||
"concurrently": "^8.2.0",
|
||||
"cssnano": "^6.0.1",
|
||||
"postcss": "^8.2.6",
|
||||
"postcss-import": "^14.0.0",
|
||||
"postcss-preset-env": "^6.7.0",
|
||||
"postcss-import": "^15.0.0",
|
||||
"postcss-preset-env": "^8.0.1",
|
||||
"watch": "^1.0.2"
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,6 @@
|
||||
module.exports = {
|
||||
const { config } = require("@swc/core/spack");
|
||||
|
||||
module.exports = config({
|
||||
entry: {
|
||||
'scripts.min': __dirname + '/js/index.js',
|
||||
'tables.min': __dirname + '/js/base/sort-tables.js',
|
||||
@ -8,12 +10,15 @@ module.exports = {
|
||||
},
|
||||
options: {
|
||||
jsc: {
|
||||
target: 'es3',
|
||||
loose: true,
|
||||
parser: {
|
||||
syntax: "ecmascript",
|
||||
jsx: false,
|
||||
},
|
||||
target: 'es2016',
|
||||
loose: false,
|
||||
},
|
||||
minify: true,
|
||||
module: {
|
||||
type: 'es6'
|
||||
}
|
||||
}
|
||||
sourceMaps: false,
|
||||
isModule: true,
|
||||
}
|
||||
});
|
File diff suppressed because it is too large
Load Diff
12
index.php
12
index.php
@ -4,11 +4,9 @@
|
||||
*
|
||||
* An API client for Kitsu to manage anime and manga watch lists
|
||||
*
|
||||
* PHP version 8
|
||||
* PHP version 8.1
|
||||
*
|
||||
* @package HummingbirdAnimeClient
|
||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
||||
* @copyright 2015 - 2021 Timothy J. Warren
|
||||
* @copyright 2015 - 2023 Timothy J. Warren <tim@timshome.page>
|
||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
||||
* @version 5.2
|
||||
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
||||
@ -25,8 +23,8 @@ setlocale(LC_CTYPE, 'en_US');
|
||||
// Load composer autoloader
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
Debugger::$strictMode = true;
|
||||
Debugger::$showBar = false;
|
||||
Debugger::$strictMode = E_ALL;
|
||||
Debugger::$showBar = FALSE;
|
||||
Debugger::enable(Debugger::DEVELOPMENT, __DIR__ . '/app/logs');
|
||||
|
||||
// Define base directories
|
||||
@ -37,7 +35,7 @@ $CONF_DIR = _dir($APP_DIR, 'config');
|
||||
// -----------------------------------------------------------------------------
|
||||
// Dependency Injection setup
|
||||
// -----------------------------------------------------------------------------
|
||||
$baseConfig = require "{$APPCONF_DIR}/base_config.php";
|
||||
$baseConfig = require _dir($APPCONF_DIR, 'base_config.php');
|
||||
$di = require "{$APP_DIR}/bootstrap.php";
|
||||
|
||||
$config = loadConfig($CONF_DIR);
|
||||
|
67
justfile
Normal file
67
justfile
Normal file
@ -0,0 +1,67 @@
|
||||
# Lists the available actions
|
||||
default:
|
||||
@just --list
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Front-end stuff
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
# Builds/optimizes JS and CSS
|
||||
build:
|
||||
cd frontEndSrc && npm run build && cd ..
|
||||
|
||||
# Builds/optimizes CSS
|
||||
css:
|
||||
composer run-script build:css
|
||||
|
||||
# Builds/optimizes JS
|
||||
js:
|
||||
composer run-script build:js
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Code Quality and Formatting
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
# Check code formatting
|
||||
check-fmt:
|
||||
tools/vendor/bin/php-cs-fixer fix --dry-run --verbose
|
||||
|
||||
# Fix code formatting
|
||||
fmt:
|
||||
tools/vendor/bin/php-cs-fixer fix --verbose
|
||||
|
||||
# Runs phpstan code check
|
||||
phpstan:
|
||||
composer run-script phpstan
|
||||
|
||||
# Runs rector, showing what changes will be make
|
||||
rector-dry-run:
|
||||
tools/vendor/bin/rector process --config=tools/rector.php --dry-run src tests
|
||||
|
||||
# Runs rector, and updates the source files
|
||||
rector:
|
||||
tools/vendor/bin/rector process --config=tools/rector.php src tests
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Testing
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
# Run tests
|
||||
test:
|
||||
composer run-script test
|
||||
|
||||
# Run tests, update snapshots
|
||||
test-update:
|
||||
composer run-script test-update
|
||||
|
||||
# Run unit tests and generate test-coverage report
|
||||
coverage:
|
||||
composer run-script coverage
|
||||
|
||||
# -------------------------------------------------------------------
|
||||
# Misc
|
||||
# -------------------------------------------------------------------
|
||||
|
||||
# Update the per-file header comments
|
||||
update-headers:
|
||||
php tools/update_header_comments.php
|
@ -2,7 +2,8 @@
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class FirstMigration extends AbstractMigration {
|
||||
class FirstMigration extends AbstractMigration
|
||||
{
|
||||
/**
|
||||
* Migrate up
|
||||
*/
|
||||
@ -25,11 +26,11 @@ class FirstMigration extends AbstractMigration {
|
||||
// Create anime_set table
|
||||
$anime_set = $this->table('anime_set', ['id' => FALSE, 'primary_key' => ['hummingbird_id']]);
|
||||
$anime_set->addColumn('hummingbird_id', 'biginteger')
|
||||
->addColumn('slug', 'string', ['comment' => "URL slug used for image caching and generating links"])
|
||||
->addColumn('slug', 'string', ['comment' => 'URL slug used for image caching and generating links'])
|
||||
->addColumn('title', 'string')
|
||||
->addColumn('alternate_title', 'string', ['null' => TRUE])
|
||||
->addColumn('media_id', 'integer', ['default' => 3, 'null' => TRUE])
|
||||
->addColumn('show_type', 'string', ['default' => 'TV', 'null' => TRUE, 'comment' => "TV Series/OVA/etc"])
|
||||
->addColumn('show_type', 'string', ['default' => 'TV', 'null' => TRUE, 'comment' => 'TV Series/OVA/etc'])
|
||||
->addColumn('age_rating', 'string', ['default' => 'PG13', 'null' => TRUE])
|
||||
->addColumn('cover_image', 'string', ['null' => TRUE])
|
||||
->addColumn('episode_count', 'integer', ['null' => TRUE])
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
@ -11,7 +11,7 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
|
||||
{
|
||||
$newLinkTable = $this->table('anime_set_media_link', [
|
||||
'id' => FALSE,
|
||||
'primary_key' => ['hummingbird_id', 'media_id']
|
||||
'primary_key' => ['hummingbird_id', 'media_id'],
|
||||
]);
|
||||
|
||||
$newLinkTable->addColumn('hummingbird_id', 'biginteger')
|
||||
@ -31,6 +31,7 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
|
||||
foreach ($rows as $row)
|
||||
{
|
||||
$keys = array_keys($row);
|
||||
|
||||
foreach ($keys as $k)
|
||||
{
|
||||
if (is_numeric($k))
|
||||
@ -49,6 +50,7 @@ class ReorganizeAnimeCollectionMedia extends AbstractMigration
|
||||
// and replace those rows with the individual entries
|
||||
$linkRows = $this->fetchAll('SELECT hummingbird_id FROM anime_set_media_link WHERE media_id=1');
|
||||
$insertRows = [];
|
||||
|
||||
foreach ($linkRows as $row)
|
||||
{
|
||||
$insertRows[] = [
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
@ -18,6 +18,7 @@ class AnimeCollectionRefactorCleanup extends AbstractMigration
|
||||
{
|
||||
// Add some new media types
|
||||
$moreMediaTypes = [];
|
||||
|
||||
foreach ($this->newMediaTypes as $id => $medium)
|
||||
{
|
||||
$moreMediaTypes[] = [
|
||||
@ -47,7 +48,7 @@ class AnimeCollectionRefactorCleanup extends AbstractMigration
|
||||
$this->execute("UPDATE media SET type='Bootleg DVD' WHERE id=4");
|
||||
|
||||
// Remove the new media types
|
||||
$values = array_map(fn ($medium) => "'{$medium}'", $this->newMediaTypes);
|
||||
$values = array_map(static fn ($medium) => "'{$medium}'", $this->newMediaTypes);
|
||||
$valueList = implode(',', $values);
|
||||
$this->execute("DELETE FROM media WHERE type IN ({$valueList})");
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
<?php
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
|
@ -9,11 +9,12 @@ parameters:
|
||||
- ./console
|
||||
- index.php
|
||||
ignoreErrors:
|
||||
- "#Offset 'fields' does not exist on array#"
|
||||
- '#Function imagepalletetotruecolor not found#'
|
||||
- '#Unable to resolve the template type T#'
|
||||
- '#imagepalletetotruecolor not found#'
|
||||
- '#Call to an undefined method Aura\\\Html\\\HelperLocator::[a-zA-Z0-9_]+\(\)#'
|
||||
- '#Call to an undefined method Query\\QueryBuilderInterface::[a-zA-Z0-9_]+\(\)#'
|
||||
excludes_analyse:
|
||||
excludePaths:
|
||||
- src/Ion/Type/Stringy.php
|
||||
- tests/mocks.php
|
||||
- vendor
|
||||
# These are objects that basically can return anything
|
||||
|
2
public/css/auto.min.css
vendored
2
public/css/auto.min.css
vendored
File diff suppressed because one or more lines are too long
2
public/css/dark.min.css
vendored
2
public/css/dark.min.css
vendored
File diff suppressed because one or more lines are too long
2
public/css/light.min.css
vendored
2
public/css/light.min.css
vendored
File diff suppressed because one or more lines are too long
Binary file not shown.
Before Width: | Height: | Size: 807 B |
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user