Skip to content

Commit

Permalink
Respect PSR-2 coding standard
Browse files Browse the repository at this point in the history
  • Loading branch information
phansys committed Jan 21, 2020
1 parent 2a1d4d9 commit 20febf8
Show file tree
Hide file tree
Showing 11 changed files with 550 additions and 403 deletions.
53 changes: 53 additions & 0 deletions .php_cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

// Use PHP-CS-Fixer 2+ if it is available
if (\class_exists('PhpCsFixer\Config', false)) {
return require __DIR__.'/.php_cs.dist';
}

$header = <<<'EOF'
This file is part of PhpZabbixApi.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@copyright The MIT License (MIT)
@author confirm IT solutions GmbH, Rathausstrase 14, CH-6340 Baar
EOF;

return Symfony\CS\Config\Config::create()
->setUsingCache(true)
->fixers(array(
'newline_after_open_tag',
'no_useless_else',
'no_useless_return',
'ordered_use',
'php_unit_construct',
'-phpdoc_annotation_without_dot',
'-phpdoc_params',
'-phpdoc_to_comment',
'-psr0',
'unalign_double_arrow',
'unalign_equals',
))
->finder(
Symfony\CS\Finder\DefaultFinder::create()
->in(__DIR__)
->exclude(array('vendor', 'build/templates'))
)
;
108 changes: 108 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

$header = <<<'EOF'
This file is part of PhpZabbixApi.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
@copyright The MIT License (MIT)
@author confirm IT solutions GmbH, Rathausstrase 14, CH-6340 Baar
EOF;

// Use PHP-CS-Fixer 2+ if it is available
return PhpCsFixer\Config::create()
->setUsingCache(true)
->setRiskyAllowed(true)
->setRules(array(
'@PSR2' => true,
'@Symfony' => true,
'@Symfony:risky' => true,
'align_multiline_comment' => true,
'array_indentation' => true,
'array_syntax' => array('syntax' => 'long'),
'blank_line_before_statement' => true,
'combine_consecutive_issets' => true,
'combine_consecutive_unsets' => true,
'declare_strict_types' => false,
'dir_constant' => true,
'ereg_to_preg' => true,
'explicit_string_variable' => true,
'global_namespace_import' => array('import_classes' => false),
'header_comment' => array('header' => $header),
'heredoc_to_nowdoc' => true,
'linebreak_after_opening_tag' => true,
'logical_operators' => true,
'method_argument_space' => true,
'multiline_whitespace_before_semicolons' => true,
'native_function_invocation' => false,
'no_alternative_syntax' => true,
'no_empty_comment' => true,
'no_extra_consecutive_blank_lines' => array(
'break',
'continue',
'extra',
'return',
'throw',
'use',
'parenthesis_brace_block',
'square_brace_block',
'curly_brace_block',
),
'no_homoglyph_names' => true,
'no_null_property_initialization' => true,
'no_short_echo_tag' => true,
'no_spaces_inside_parenthesis' => true,
'no_superfluous_elseif' => true,
'no_superfluous_phpdoc_tags' => array('allow_mixed' => true),
'no_unneeded_curly_braces' => true,
'no_unneeded_final_method' => true,
'no_unreachable_default_argument_value' => true,
'no_unset_on_property' => true,
'no_useless_else' => true,
'no_useless_return' => true,
'no_whitespace_in_blank_line' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_add_missing_param_annotation' => true,
'phpdoc_align' => false,
'phpdoc_order' => true,
'phpdoc_summary' => false,
'phpdoc_to_comment' => false,
'phpdoc_trim_consecutive_blank_line_separation' => true,
'phpdoc_types_order' => array(
'null_adjustment' => 'always_last',
'sort_algorithm' => 'none',
),
'phpdoc_var_annotation_correct_order' => true,
'php_unit_construct' => true,
'php_unit_set_up_tear_down_visibility' => true,
'php_unit_strict' => true,
'pow_to_exponentiation' => true,
'psr4' => true,
'return_assignment' => true,
'single_line_comment_style' => true,
'void_return' => false,
'yoda_style' => true,
))
->setFinder(
PhpCsFixer\Finder::create()
->in(__DIR__)
->exclude(array('vendor', 'build/templates'))
)
;
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,4 @@ install:

script:
- ./vendor/bin/phpunit
- ./vendor/bin/php-cs-fixer fix -v
73 changes: 31 additions & 42 deletions build/build.php
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,27 +1,29 @@
#!/usr/bin/env php
<?php

/**
* @file build.php
*
* @brief PHP script to build the PhpZabbixApi class(es).
*
/*
* This file is part of PhpZabbixApi.
*
* PhpZabbixApi is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* PhpZabbixApi is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* You should have received a copy of the GNU General Public License
* along with PhpZabbixApi. If not, see <http://www.gnu.org/licenses/>.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*
* @copyright GNU General Public License
* @author confirm IT solutions GmbH, Rathausstrase 14, CH-6340 Baar
* @copyright The MIT License (MIT)
* @author confirm IT solutions GmbH, Rathausstrase 14, CH-6340 Baar
*/

if (!in_array(PHP_SAPI, array('cli', 'phpdbg', 'embed'), true)) {
Expand All @@ -30,15 +32,11 @@

set_time_limit(0);

/*
* Load required files.
*/
// Load required files.
require __DIR__.'/config.inc.php';
require __DIR__.'/replacePlaceholders.func.php';

/*
* Define some pathes and do some sanity checks for existence of the pathes.
*/
// Define some pathes and do some sanity checks for existence of the pathes.

if (!is_dir(PATH_ZABBIX)) {
throw new RuntimeException('ERROR: Zabbix path "'.PATH_ZABBIX.'" is not a directory! Please check the PATH_ZABBIX configuration constant.');
Expand All @@ -48,7 +46,7 @@
require PATH_ZABBIX.'/include/defines.inc.php';

/**
* @brief Path to the API.php class file of the Zabbix PHP front-end.
* Path to the API.php class file of the Zabbix PHP front-end.
*
* This class file will be used, to determine all available API classes.
*/
Expand All @@ -59,7 +57,7 @@
}

/**
* @brief Path to the api/classes/ directory of the Zabbix PHP front-end.
* Path to the api/classes/ directory of the Zabbix PHP front-end.
*
* This directory and the contained class files will be used, to determine all
* available methods for each API class.
Expand All @@ -74,9 +72,7 @@
throw new RuntimeException('ERROR: API class directory "'.PATH_ZABBIX_API_CLASSES_DIRECTORY.'" not found!');
}

/*
* Initialize.
*/
// Initialize.

// set template placeholders
$templatePlaceholders = array(
Expand Down Expand Up @@ -117,8 +113,7 @@ class ZabbixApiClassMap extends CApiServiceFactory
{
public function getClassMap()
{
$classMap = $this->objects;
return $classMap;
return $this->objects;
}
}
} else {
Expand Down Expand Up @@ -175,15 +170,13 @@ function __autoload($className)
// loop through defined methods
foreach ($reflection->getMethods(ReflectionMethod::IS_PUBLIC & ~ReflectionMethod::IS_STATIC) as $method) {
// add action to API array
if ($method->class != 'CZBXAPI' && !($resource == 'user' && $method->name == 'login') && !($resource == 'user' && $method->name == 'logout') && !$method->isConstructor() && !$method->isDestructor() && !$method->isAbstract()) {
if ('CZBXAPI' !== $method->class && !('user' === $resource && 'login' === $method->name) && !('user' === $resource && 'logout' === $method->name) && !$method->isConstructor() && !$method->isDestructor() && !$method->isAbstract()) {
$apiArray[$resource][] = $method->name;
}
}
}

/*
* Build abstract template.
*/
// Build abstract template.

// get template
if (!$template = file_get_contents(PATH_TEMPLATES.'/abstract.tpl.php')) {
Expand All @@ -194,7 +187,7 @@ function __autoload($className)
preg_match('/(.*)<!START_API_METHOD>(.*)<!END_API_METHOD>(.*)/s', $template, $matches);

// sanity check
if (count($matches) != 4) {
if (4 !== count($matches)) {
throw new RuntimeException('Template "'.PATH_TEMPLATES.'"/abstract.tpl.php parsing failed!');
}

Expand All @@ -206,7 +199,7 @@ function __autoload($className)
foreach ($actions as $action) {
$methodPlaceholders = array(
'API_METHOD' => $resource.'.'.$action,
'PHP_METHOD' => $resource.ucfirst($action)
'PHP_METHOD' => $resource.ucfirst($action),
);
$apiMethods .= replacePlaceholders($matches[2], $methodPlaceholders);
}
Expand All @@ -222,9 +215,7 @@ function __autoload($className)

echo 'BUILT: abstract class file "'.PATH_BUILD.'/'.FILENAME_ABSTRACT.'"'."\n";

/*
* Build concrete template.
*/
// Build concrete template.

if (!file_exists(PATH_BUILD.'/'.FILENAME_CONCRETE)) {
// get template
Expand All @@ -245,9 +236,7 @@ function __autoload($className)
echo 'SKIPPED: concrete class file "'.PATH_BUILD.'/'.FILENAME_CONCRETE.'"'."\n";
}

/*
* Build exception template.
*/
// Build exception template.

if (!file_exists(PATH_BUILD.'/'.FILENAME_EXCEPTION)) {
// get template
Expand Down
Loading

0 comments on commit 20febf8

Please sign in to comment.