Skip to content

Commit

Permalink
Update to PSR-12 coding standard. (#22)
Browse files Browse the repository at this point in the history
  • Loading branch information
demiankatz committed Mar 17, 2023
1 parent 24762ba commit 5292532
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 45 deletions.
4 changes: 2 additions & 2 deletions build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@

<!-- php-cs-fixer (first task applies fixes, second task simply checks if they are needed) -->
<target name="php-cs-fixer">
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind.php_cs --verbose" passthru="true" escape="false" />
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind.php-cs-fixer.php --verbose" passthru="true" escape="false" />
</target>
<target name="php-cs-fixer-dryrun">
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind.php_cs --dry-run --verbose --diff" passthru="true" escape="false" checkreturn="true" />
<exec command="${srcdir}/vendor/bin/php-cs-fixer fix --config=${srcdir}/tests/vufind.php-cs-fixer.php --dry-run --verbose --diff" passthru="true" escape="false" checkreturn="true" />
</target>

<!-- PHP API Documentation -->
Expand Down
1 change: 1 addition & 0 deletions src/VuFindHttp/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindHttp\Exception;

/**
Expand Down
1 change: 1 addition & 0 deletions src/VuFindHttp/Exception/RuntimeException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindHttp\Exception;

/**
Expand Down
1 change: 1 addition & 0 deletions src/VuFindHttp/HttpService.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindHttp;

/**
Expand Down
1 change: 1 addition & 0 deletions src/VuFindHttp/HttpServiceAwareInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindHttp;

/**
Expand Down
2 changes: 2 additions & 0 deletions src/VuFindHttp/HttpServiceAwareTrait.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* Default implementation of HttpServiceAwareInterface.
*
Expand All @@ -25,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindHttp;

/**
Expand Down
1 change: 1 addition & 0 deletions src/VuFindHttp/HttpServiceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindHttp;

/**
Expand Down
26 changes: 23 additions & 3 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,30 @@
/**
* Proxy service PHPUnit bootstrap.
*
* @author David Maus <maus@hab.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @copyright Copyright (C) Villanova University 2011
* PHP version 7
*
* Copyright (C) Villanova University 2011-2023.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* This program 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
* @category VuFind
* @package Tests
* @author David Maus <maus@hab.de>
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development:testing:unit_tests Wiki
*/

if (file_exists('vendor/autoload.php')) {
require_once 'vendor/autoload.php';
}
19 changes: 15 additions & 4 deletions tests/phpcs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@
<ruleset name="VuFind Coding Standards" namespace="VuFind\PHPCS">
<description>Coding standards for VuFind.</description>
<file>../src</file>
<file>.</file>
<exclude-pattern>*/config/*</exclude-pattern>
<exclude-pattern>*/tests/*</exclude-pattern>
<exclude-pattern>*.php-cs-fixer.*</exclude-pattern>
<arg name="extensions" value="php"/>
<rule ref="PEAR">
<!-- We only use PEAR to ensure complete comments at this time -->
<rule ref="PEAR.Commenting">
<exclude name="PEAR.Commenting.FunctionComment.ParamCommentAlignment" />
<exclude name="PEAR.WhiteSpace.ScopeIndent.IncorrectExact" />
<exclude name="PEAR.WhiteSpace.ScopeIndent.Incorrect" />
</rule>
<rule ref="Generic.NamingConventions.UpperCaseConstantName"/>
<rule ref="Generic.Commenting.DocComment"/>
<rule ref="Squiz.Commenting.DocCommentAlignment"/>
<!-- Lines can be 120 chars long, but never show errors -->
<rule ref="Generic.Files.LineLength">
<properties>
<property name="lineLimit" value="120"/>
<property name="absoluteLineLimit" value="0"/>
</properties>
</rule>
<rule ref="PSR12" />
</ruleset>
11 changes: 5 additions & 6 deletions tests/unit-tests/src/VuFindTest/HttpServiceAwareTraitTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* HttpServiceAwareTrait unit test.
*
Expand All @@ -25,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindTest;

/**
Expand Down Expand Up @@ -63,7 +65,9 @@ class HttpServiceAwareTraitTest extends \PHPUnit\Framework\TestCase
public function testSetHttpService()
{
$mock = $this->getMockBuilder('VuFindHttp\HttpService')->getMock();
$test = new HttpServiceAwareTraitTestImplementation();
$test = new class () {
use \VuFindHttp\HttpServiceAwareTrait;
};
$test->setHttpService($mock);
$this->assertEquals($mock, $this->getProperty($test, 'httpService'));
}
Expand All @@ -87,8 +91,3 @@ protected function getProperty($object, $property)
return $reflectionProperty->getValue($object);
}
}

class HttpServiceAwareTraitTestImplementation
{
use \VuFindHttp\HttpServiceAwareTrait;
}
26 changes: 21 additions & 5 deletions tests/unit-tests/src/VuFindTest/HttpServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License
* @link https://vufind.org/wiki/development
*/

namespace VuFindTest;

use VuFindHttp\HttpService as Service;
Expand Down Expand Up @@ -159,11 +160,20 @@ public function testGetAppendsHeaders()
),
$this->equalTo('1.1'),
$this->equalTo(
['Host' => 'example.tld', 'Connection' => 'close', 'Accept-Encoding' => 'gzip, deflate','User-Agent' => 'Laminas_Http_Client', 'Content-Type' => 'application/json', 'Accept' => 'application/json']
[
'Host' => 'example.tld', 'Connection' => 'close', 'Accept-Encoding' => 'gzip, deflate',
'User-Agent' => 'Laminas_Http_Client', 'Content-Type' => 'application/json',
'Accept' => 'application/json'
]
)
);
$service->setDefaultAdapter($adapter);
$service->get('http://example.tld', ['foo=bar'], 'test', ["Content-type: application/json", "Accept: application/json"]);
$service->get(
'http://example.tld',
['foo=bar'],
'test',
["Content-type: application/json", "Accept: application/json"]
);
}

/**
Expand All @@ -185,7 +195,11 @@ public function testPostAppendsHeaders()
),
$this->equalTo('1.1'),
$this->equalTo(
['Host' => 'example.tld', 'Connection' => 'close', 'Accept-Encoding' => 'gzip, deflate','User-Agent' => 'Laminas_Http_Client', 'Content-Type' => 'application/json', 'Accept' => 'application/json', 'Content-Length' => '5']
[
'Host' => 'example.tld', 'Connection' => 'close', 'Accept-Encoding' => 'gzip, deflate',
'User-Agent' => 'Laminas_Http_Client', 'Content-Type' => 'application/json',
'Accept' => 'application/json', 'Content-Length' => '5'
]
)
);
$service->setDefaultAdapter($adapter);
Expand Down Expand Up @@ -303,7 +317,8 @@ public function testProxifySocks5()
$this->assertEquals('localhost', $config['curloptions'][CURLOPT_PROXY]);
$this->assertEquals('666', $config['curloptions'][CURLOPT_PROXYPORT]);
$this->assertEquals(
CURLPROXY_SOCKS5, $config['curloptions'][CURLOPT_PROXYTYPE]
CURLPROXY_SOCKS5,
$config['curloptions'][CURLOPT_PROXYTYPE]
);
$this->assertNotContains(CURLOPT_FOLLOWLOCATION, $config['curloptions']);
}
Expand Down Expand Up @@ -483,7 +498,8 @@ public function testCurlAdapterFollowLocation()
$this->assertInstanceOf('Laminas\Http\Client\Adapter\Curl', $adapter);
$config = $adapter->getConfig();
$this->assertEquals(
'1', $config['curloptions'][CURLOPT_FOLLOWLOCATION] ?? null
'1',
$config['curloptions'][CURLOPT_FOLLOWLOCATION] ?? null
);
}

Expand Down
28 changes: 3 additions & 25 deletions tests/vufind.php_cs → tests/vufind.php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,41 +1,29 @@
<?php

$finder = new PhpCsFixer\Finder();
$finder->in(__DIR__ . '/../src');
$finder->in(__DIR__)
->in(__DIR__ . '/../src');

$rules = [
'@PSR12' => true,
'align_multiline_comment' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
'operators' => ['=' => null, '=>' => null],
],
'blank_line_after_namespace' => true,
'braces' => true,
'cast_spaces' => ['space' => 'none'],
'class_attributes_separation' => ['elements' => ['method' => 'one', 'property' => 'one']],
'concat_space' => ['spacing' => 'one'],
'constant_case' => ['case' => 'lower'],
'elseif' => true,
'encoding' => true,
'ereg_to_preg' => true,
'full_opening_tag' => true,
'function_declaration' => true,
'function_typehint_space' => true,
'indentation_type' => true,
'is_null' => true,
'line_ending' => true,
'linebreak_after_opening_tag' => true,
'list_syntax' => ['syntax' => 'short'],
'lowercase_cast' => true,
'lowercase_keywords' => true,
'magic_constant_casing' => true,
'method_argument_space' => true,
'native_function_casing' => true,
'no_blank_lines_after_class_opening' => true,
'no_blank_lines_after_phpdoc' => true,
'no_blank_lines_before_namespace' => true,
'no_closing_tag' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_empty_statement' => true,
Expand All @@ -44,11 +32,7 @@
'no_leading_namespace_whitespace' => true,
'no_mixed_echo_print' => true,
'no_singleline_whitespace_before_semicolons' => true,
'no_spaces_after_function_name' => true,
'no_spaces_around_offset' => true,
'no_spaces_inside_parenthesis' => true,
'no_trailing_whitespace' => true,
'no_trailing_whitespace_in_comment' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unused_imports' => true,
Expand All @@ -64,17 +48,11 @@
'php_unit_mock' => true,
'php_unit_no_expectation_annotation' => true,
'pow_to_exponentiation' => true,
'single_blank_line_at_eof' => true,
'single_class_element_per_statement' => true,
'single_import_per_statement' => true,
'single_line_after_imports' => true,
'short_scalar_cast' => true,
'standardize_not_equals' => true,
'switch_case_semicolon_to_colon' => true,
'switch_case_space' => true,
'ternary_operator_spaces' => true,
'ternary_to_null_coalescing' => true,
'visibility_required' => true,
];

$cacheDir = __DIR__ . '/../.php_cs_cache';
Expand Down

0 comments on commit 5292532

Please sign in to comment.