Browse Source

Apply house style

master
J. King 4 years ago
parent
commit
2e9598b18b
  1. 1
      .gitignore
  2. 79
      .php_cs.dist
  3. 1
      lib/Collection.php
  4. 2
      lib/Date.php
  5. 4
      lib/Exception.php
  6. 3
      lib/Parser/Construct.php
  7. 2
      lib/Parser/JSON/Entry.php
  8. 1
      lib/Parser/JSON/Feed.php
  9. 2
      lib/Parser/XML/Construct.php
  10. 12
      lib/Parser/XML/Feed.php
  11. 3
      lib/Parser/XML/Primitives/Entry.php
  12. 5
      lib/Parser/XML/Primitives/Feed.php
  13. 6
      lib/Sanitizer.php
  14. 1
      tests/cases/JSON/JSONTest.php
  15. 112
      tests/cases/Util/Url/AbstractUriTestCase.php
  16. 5
      vendor-bin/csfixer/composer.json
  17. 1383
      vendor-bin/csfixer/composer.lock

1
.gitignore

@ -2,3 +2,4 @@
/vendor-bin/*/vendor /vendor-bin/*/vendor
/tests/coverage /tests/coverage
/tests/.phpunit.result.cache /tests/.phpunit.result.cache
/.php_cs.cache

79
.php_cs.dist

@ -0,0 +1,79 @@
<?php
declare(strict_types=1);
const BASE = __DIR__.DIRECTORY_SEPARATOR;
$paths = [
__FILE__,
BASE."RoboFile.php",
BASE."lib",
BASE."tests",
];
$rules = [
// house rules where PSR series is silent
'align_multiline_comment' => ['comment_type' => "phpdocs_only"],
'array_syntax' => ['syntax' => "short"],
'binary_operator_spaces' => [
'default' => "single_space",
'operators' => ['=>' => "align_single_space"],
],
'cast_spaces' => ['space' => "single"],
'concat_space' => ['spacing' => "none"],
'list_syntax' => ['syntax' => "short"],
'magic_constant_casing' => true,
'magic_method_casing' => true,
'modernize_types_casting' => true,
'native_function_casing' => true,
'native_function_type_declaration_casing' => true,
'no_binary_string' => true,
'no_blank_lines_after_phpdoc' => true,
'no_empty_comment' => true,
'no_empty_phpdoc' => true,
'no_extra_blank_lines' => true, // this could probably use more configuration
'no_mixed_echo_print' => ['use' => "echo"],
'no_short_bool_cast' => true,
'no_trailing_comma_in_singleline_array' => true,
'no_unneeded_control_parentheses' => true,
'no_unneeded_curly_braces' => true,
'no_unused_imports' => true,
'no_whitespace_before_comma_in_array' => true,
'normalize_index_brace' => true,
'object_operator_without_whitespace' => true,
'pow_to_exponentiation' => true,
'set_type_to_cast' => true,
'standardize_not_equals' => true,
'trailing_comma_in_multiline_array' => true,
'unary_operator_spaces' => true,
'yoda_style' => false,
// PSR standard to apply
'@PSR2' => true,
// PSR-12 rules; php-cs-fixer does not yet support PSR-12 natively
'compact_nullable_typehint' => true,
'declare_equal_normalize' => ['space' => "none"],
'function_typehint_space' => true,
'lowercase_cast' => true,
'lowercase_static_reference' => true,
'no_alternative_syntax' => true,
'no_empty_statement' => true,
'no_leading_import_slash' => true,
'no_leading_namespace_whitespace' => true,
'no_whitespace_in_blank_line' => true,
'return_type_declaration' => ['space_before' => "none"],
'single_trait_insert_per_statement' => true,
'short_scalar_cast' => true,
'visibility_required' => ['elements' => ["const", "property", "method"]],
// house exceptions to PSR rules
'braces' => ['position_after_functions_and_oop_constructs' => "same"],
'function_declaration' => ['closure_function_spacing' => "none"],
'new_with_braces' => false, // no option to specify absence of braces
];
$finder = \PhpCsFixer\Finder::create();
foreach ($paths as $path) {
if (is_file($path)) {
$finder = $finder->append([$path]);
} else {
$finder = $finder->in($path);
}
}
return \PhpCsFixer\Config::create()->setRiskyAllowed(true)->setRules($rules)->setFinder($finder);

1
lib/Collection.php

@ -7,7 +7,6 @@ declare(strict_types=1);
namespace JKingWeb\Lax; namespace JKingWeb\Lax;
abstract class Collection implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable { abstract class Collection implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable {
protected $data = []; protected $data = [];
/** Implementation for IteratorAggregate */ /** Implementation for IteratorAggregate */

2
lib/Date.php

@ -7,7 +7,7 @@ declare(strict_types=1);
namespace JKingWeb\Lax; namespace JKingWeb\Lax;
class Date extends \DateTimeImmutable implements \JsonSerializable { class Date extends \DateTimeImmutable implements \JsonSerializable {
static public $supportedFormats = [ public static $supportedFormats = [
// RFC 3339 formats // RFC 3339 formats
'Y-m-d\TH:i:s.u\Z', 'Y-m-d\TH:i:s.u\Z',
'Y-m-d\TH:i:s.u\z', 'Y-m-d\TH:i:s.u\z',

4
lib/Exception.php

@ -11,7 +11,7 @@ abstract class Exception extends \Exception {
// Parsing: 0x1100 // Parsing: 0x1100
"notJSONType" => [0x1111, "Document Content-Type is not either that of JSON Feed or generic JSON"], "notJSONType" => [0x1111, "Document Content-Type is not either that of JSON Feed or generic JSON"],
"notJSON" => [0x1112, "Document is not valid JSON"], "notJSON" => [0x1112, "Document is not valid JSON"],
"notJSONFeed" => [0x1113, "Document is not a JSON Feed document"] "notJSONFeed" => [0x1113, "Document is not a JSON Feed document"],
]; ];
public function __construct(string $symbol, \Exception $e = null) { public function __construct(string $symbol, \Exception $e = null) {
@ -19,7 +19,7 @@ abstract class Exception extends \Exception {
if (!$data) { if (!$data) {
throw new \Exception("Exception symbol \"$symbol\" does not exist"); throw new \Exception("Exception symbol \"$symbol\" does not exist");
} }
list($code, $msg) = $data; [$code, $msg] = $data;
parent::__construct($msg, $code, $e); parent::__construct($msg, $code, $e);
} }
} }

3
lib/Parser/Construct.php

@ -42,7 +42,8 @@ trait Construct {
$domain = $match[2]; $domain = $match[2];
// PHP's filter_var does not accept IDN hosts, so we have to perform an IDNA transformation first // PHP's filter_var does not accept IDN hosts, so we have to perform an IDNA transformation first
$domain = idn_to_ascii($domain, \IDNA_NONTRANSITIONAL_TO_ASCII | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ, \INTL_IDNA_VARIANT_UTS46); // settings for IDNA2008 algorithm (I think) $domain = idn_to_ascii($domain, \IDNA_NONTRANSITIONAL_TO_ASCII | \IDNA_CHECK_BIDI | \IDNA_CHECK_CONTEXTJ, \INTL_IDNA_VARIANT_UTS46); // settings for IDNA2008 algorithm (I think)
if ($domain !== false) {$addr = "$local@$domain"; if ($domain !== false) {
$addr = "$local@$domain";
return (bool) filter_var($addr, \FILTER_VALIDATE_EMAIL, \FILTER_FLAG_EMAIL_UNICODE); return (bool) filter_var($addr, \FILTER_VALIDATE_EMAIL, \FILTER_FLAG_EMAIL_UNICODE);
} }
return false; return false;

2
lib/Parser/JSON/Entry.php

@ -69,7 +69,7 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
$exp = (int) $id[1]; $exp = (int) $id[1];
$mul = $exp > -1; $mul = $exp > -1;
$exp = abs($exp); $exp = abs($exp);
list($int, $dec) = explode(".", $id[0]); [$int, $dec] = explode(".", $id[0]);
$dec = strlen($dec) ? str_split($dec, 1) : []; $dec = strlen($dec) ? str_split($dec, 1) : [];
$int = str_split($int, 1); $int = str_split($int, 1);
if ($int[0] === "-") { if ($int[0] === "-") {

1
lib/Parser/JSON/Feed.php

@ -8,7 +8,6 @@ namespace JKingWeb\Lax\Parser\JSON;
use JKingWeb\Lax\Text; use JKingWeb\Lax\Text;
use JKingWeb\Lax\Date; use JKingWeb\Lax\Date;
use JKingWeb\Lax\Entry;
use JKingWeb\Lax\Feed as FeedStruct; use JKingWeb\Lax\Feed as FeedStruct;
use JKingWeb\Lax\Person\Collection as PersonCollection; use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection; use JKingWeb\Lax\Category\Collection as CategoryCollection;

2
lib/Parser/XML/Construct.php

@ -15,7 +15,7 @@ trait Construct {
use \JKingWeb\Lax\Parser\Construct; use \JKingWeb\Lax\Parser\Construct;
/** @var \DOMDocument */ /** @var \DOMDocument */
public $document; protected $document;
/** @var \DOMXPath */ /** @var \DOMXPath */
protected $xpath; protected $xpath;
/** @var \DOMElement */ /** @var \DOMElement */

12
lib/Parser/XML/Feed.php

@ -24,8 +24,6 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
protected $contentType; protected $contentType;
/** @var \JKingWeb\Lax\Url */ /** @var \JKingWeb\Lax\Url */
protected $url; protected $url;
/** @var \DOMDocument */
protected $document;
/** @var \DOMElement */ /** @var \DOMElement */
protected $subject; protected $subject;
/** @var \DOMXpath */ /** @var \DOMXpath */
@ -49,23 +47,23 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
$this->subject = $this->document->documentElement; $this->subject = $this->document->documentElement;
$ns = $this->subject->namespaceURI; $ns = $this->subject->namespaceURI;
$name = $this->subject->localName; $name = $this->subject->localName;
if (is_null($ns) && $name=="rss") { if (is_null($ns) && $name === "rss") {
$this->subject = $this->fetchElement("channel") ?? $this->subject; $this->subject = $this->fetchElement("channel") ?? $this->subject;
$feed->format = "rss"; $feed->format = "rss";
$feed->version = $this->document->documentElement->getAttribute("version"); $feed->version = $this->document->documentElement->getAttribute("version");
} elseif ($ns==XPath::NS['rdf'] && $name=="RDF") { } elseif ($ns === XPath::NS['rdf'] && $name === "RDF") {
$feed->format = "rdf"; $feed->format = "rdf";
$channel = $this->fetchElement("rss1:channel|rss0:channel"); $channel = $this->fetchElement("rss1:channel|rss0:channel");
if ($channel) { if ($channel) {
$this->subject = $channel; $this->subject = $channel;
$feed->version = ($channel->namespaceURI==XPath::NS['rss1']) ? "1.0" : "0.90"; $feed->version = ($channel->namespaceURI === XPath::NS['rss1']) ? "1.0" : "0.90";
} else { } else {
$element = $this->fetchElement("rss1:item|rss0:item|rss1:image|rss0:image"); $element = $this->fetchElement("rss1:item|rss0:item|rss1:image|rss0:image");
if ($element) { if ($element) {
$feed->version = ($element->namespaceURI==XPath::NS['rss1']) ? "1.0" : "0.90"; $feed->version = ($element->namespaceURI === XPath::NS['rss1']) ? "1.0" : "0.90";
} }
} }
} elseif ($ns==XPath::NS['atom'] && $name=="feed") { } elseif ($ns === XPath::NS['atom'] && $name === "feed") {
$feed->format = "atom"; $feed->format = "atom";
$feed->version = "1.0"; $feed->version = "1.0";
} else { } else {

3
lib/Parser/XML/Primitives/Entry.php

@ -6,7 +6,6 @@
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Lax\Parser\XML\Primitives; namespace JKingWeb\Lax\Parser\XML\Primitives;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Parser\XML\XPath; use JKingWeb\Lax\Parser\XML\XPath;
trait Entry { trait Entry {
@ -22,7 +21,7 @@ trait Entry {
protected function getUrlRss1() { protected function getUrlRss1() {
// XPath doesn't seem to like the query we'd need for this, so it must be done the hard way. // XPath doesn't seem to like the query we'd need for this, so it must be done the hard way.
$node = $this->subject; $node = $this->subject;
if ($node->localName=="item" && ($node->namespaceURI==XPath::NS['rss1'] || $node->namespaceURI==XPath::NS['rss0']) && $node->hasAttributeNS(XPath::NS['rdf'], "about")) { if ($node->localName === "item" && ($node->namespaceURI === XPath::NS['rss1'] || $node->namespaceURI == XPath::NS['rss0']) && $node->hasAttributeNS(XPath::NS['rdf'], "about")) {
return $this->resolveNodeUrl($node, "about", XPath::NS['rdf']); return $this->resolveNodeUrl($node, "about", XPath::NS['rdf']);
} else { } else {
return null; return null;

5
lib/Parser/XML/Primitives/Feed.php

@ -6,7 +6,6 @@
declare(strict_types=1); declare(strict_types=1);
namespace JKingWeb\Lax\Parser\XML\Primitives; namespace JKingWeb\Lax\Parser\XML\Primitives;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Parser\XML\XPath; use JKingWeb\Lax\Parser\XML\XPath;
trait Feed { trait Feed {
@ -49,8 +48,8 @@ trait Feed {
$node = $this->subject; $node = $this->subject;
if ($node->hasAttributeNS(XPath::NS['rdf'], "about")) { if ($node->hasAttributeNS(XPath::NS['rdf'], "about")) {
if ( if (
($node->localName=="channel" && ($node->namespaceURI==XPath::NS['rss1'] || $node->namespaceURI==XPath::NS['rss0'])) || ($node->localName === "channel" && ($node->namespaceURI === XPath::NS['rss1'] || $node->namespaceURI === XPath::NS['rss0'])) ||
($node==$node->ownerDocument->documentElement && $node->localName=="RDF" && $node->namespaceURI==XPath::NS['rdf']) ($node === $node->ownerDocument->documentElement && $node->localName === "RDF" && $node->namespaceURI === XPath::NS['rdf'])
) { ) {
return $this->resolveNodeUrl($node, "about", XPath::NS['rdf']); return $this->resolveNodeUrl($node, "about", XPath::NS['rdf']);
} }

6
lib/Sanitizer.php

@ -216,13 +216,13 @@ class Sanitizer {
*/ */
public function processDocument(\DOMDocument $doc, string $url): \DOMDocument { public function processDocument(\DOMDocument $doc, string $url): \DOMDocument {
// determine if the document is non-XML HTML // determine if the document is non-XML HTML
$isHtml = ($doc->documentElement->tagName=="html" && $doc->documentElement->namespaceURI==""); $isHtml = ($doc->documentElement->tagName === "html" && $doc->documentElement->namespaceURI === "");
// loop through each element in the document // loop through each element in the document
foreach ((new \DOMXPath($doc))->query("//*") as $node) { foreach ((new \DOMXPath($doc))->query("//*") as $node) {
// resolve a qualified name for the element // resolve a qualified name for the element
if (($isHtml && $node->namespaceURI=="") || $node->namespaceURI=="http://www.w3.org/1999/xhtml") { if (($isHtml && $node->namespaceURI === "") || $node->namespaceURI === "http://www.w3.org/1999/xhtml") {
$qName = "html:".$node->tagName; $qName = "html:".$node->tagName;
} elseif ($node->namespaceURI=="") { } elseif ($node->namespaceURI === "") {
$qName = $node->tagName; $qName = $node->tagName;
} elseif (isset($this->namespaces[$node->namespaceURI])) { } elseif (isset($this->namespaces[$node->namespaceURI])) {
$qName = $this->namespaces[$node->namespaceURI].":".$node->tagName; $qName = $this->namespaces[$node->namespaceURI].":".$node->tagName;

1
tests/cases/JSON/JSONTest.php

@ -51,7 +51,6 @@ use JKingWeb\Lax\Enclosure\Collection as EnclosureCollection;
use Symfony\Component\Yaml\Yaml; use Symfony\Component\Yaml\Yaml;
use Symfony\Component\Yaml\Parser as YamlParser; use Symfony\Component\Yaml\Parser as YamlParser;
/** /**
* @covers JKingWeb\Lax\Parser\Construct<extended> * @covers JKingWeb\Lax\Parser\Construct<extended>
* @covers JKingWeb\Lax\Parser\JSON\Feed<extended> * @covers JKingWeb\Lax\Parser\JSON\Feed<extended>

112
tests/cases/Util/Url/AbstractUriTestCase.php

@ -6,8 +6,7 @@ use Psr\Http\Message\UriInterface;
use PHPUnit\Framework\TestCase; use PHPUnit\Framework\TestCase;
use InvalidArgumentException; use InvalidArgumentException;
abstract class AbstractUriTestCase extends TestCase abstract class AbstractUriTestCase extends TestCase {
{
/** /**
* @var UriInterface * @var UriInterface
*/ */
@ -24,13 +23,11 @@ abstract class AbstractUriTestCase extends TestCase
*/ */
abstract protected function createUri($uri = ''); abstract protected function createUri($uri = '');
protected function setUp(): void protected function setUp(): void {
{
$this->uri = $this->createUri($this->uri_string); $this->uri = $this->createUri($this->uri_string);
} }
protected function tearDown(): void protected function tearDown(): void {
{
$this->uri = null; $this->uri = null;
} }
@ -41,15 +38,13 @@ abstract class AbstractUriTestCase extends TestCase
* The value returned MUST be normalized to lowercase, per RFC 3986 * The value returned MUST be normalized to lowercase, per RFC 3986
* Section 3.1. * Section 3.1.
*/ */
public function testGetScheme($scheme, $expected) public function testGetScheme($scheme, $expected) {
{
$uri = $this->uri->withScheme($scheme); $uri = $this->uri->withScheme($scheme);
$this->assertInstanceOf(UriInterface::class, $uri); $this->assertInstanceOf(UriInterface::class, $uri);
$this->assertSame($expected, $uri->getScheme(), 'Scheme must be normalized according to RFC3986'); $this->assertSame($expected, $uri->getScheme(), 'Scheme must be normalized according to RFC3986');
} }
public function schemeProvider() public function schemeProvider() {
{
return [ return [
'normalized scheme' => ['HtTpS', 'https'], 'normalized scheme' => ['HtTpS', 'https'],
'simple scheme' => ['http', 'http'], 'simple scheme' => ['http', 'http'],
@ -66,15 +61,13 @@ abstract class AbstractUriTestCase extends TestCase
* user value, with a colon (":") separating the values. * user value, with a colon (":") separating the values.
* *
*/ */
public function testGetUserInfo($user, $pass, $expected) public function testGetUserInfo($user, $pass, $expected) {
{
$uri = $this->uri->withUserInfo($user, $pass); $uri = $this->uri->withUserInfo($user, $pass);
$this->assertInstanceOf(UriInterface::class, $uri); $this->assertInstanceOf(UriInterface::class, $uri);
$this->assertSame($expected, $uri->getUserInfo(), 'UserInfo must be normalized according to RFC3986'); $this->assertSame($expected, $uri->getUserInfo(), 'UserInfo must be normalized according to RFC3986');
} }
public function userInfoProvider() public function userInfoProvider() {
{
return [ return [
'with userinfo' => ['iGoR', 'rAsMuZeN', 'iGoR:rAsMuZeN'], 'with userinfo' => ['iGoR', 'rAsMuZeN', 'iGoR:rAsMuZeN'],
'no userinfo' => ['', '', ''], 'no userinfo' => ['', '', ''],
@ -92,15 +85,13 @@ abstract class AbstractUriTestCase extends TestCase
* Section 3.2.2. * Section 3.2.2.
* *
*/ */
public function testGetHost($host, $expected) public function testGetHost($host, $expected) {
{
$uri = $this->uri->withHost($host); $uri = $this->uri->withHost($host);
$this->assertInstanceOf(UriInterface::class, $uri); $this->assertInstanceOf(UriInterface::class, $uri);
$this->assertSame($expected, $uri->getHost(), 'Host must be normalized according to RFC3986'); $this->assertSame($expected, $uri->getHost(), 'Host must be normalized according to RFC3986');
} }
public function hostProvider() public function hostProvider() {
{
return [ return [
'normalized host' => ["MaStEr.eXaMpLe.CoM", "master.example.com"], 'normalized host' => ["MaStEr.eXaMpLe.CoM", "master.example.com"],
"simple host" => ["www.example.com", "www.example.com"], "simple host" => ["www.example.com", "www.example.com"],
@ -122,15 +113,13 @@ abstract class AbstractUriTestCase extends TestCase
* If no port is present, but a scheme is present, this method MAY return * If no port is present, but a scheme is present, this method MAY return
* the standard port for that scheme, but SHOULD return null. * the standard port for that scheme, but SHOULD return null.
*/ */
public function testPort($uri, $port, $expected) public function testPort($uri, $port, $expected) {
{
$uri = $this->createUri($uri)->withPort($port); $uri = $this->createUri($uri)->withPort($port);
$this->assertInstanceOf(UriInterface::class, $uri); $this->assertInstanceOf(UriInterface::class, $uri);
$this->assertSame($expected, $uri->getPort(), 'port must be an int or null'); $this->assertSame($expected, $uri->getPort(), 'port must be an int or null');
} }
public function portProvider() public function portProvider() {
{
return [ return [
'non standard port for http' => ['http://www.example.com', 443, 443], 'non standard port for http' => ['http://www.example.com', 443, 443],
'remove port' => ['http://www.example.com', null, null], 'remove port' => ['http://www.example.com', null, null],
@ -141,13 +130,11 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group port * @group port
*/ */
public function testUriWithStandardPort() public function testUriWithStandardPort() {
{
$uri = $this->createUri('http://example.com:80'); $uri = $this->createUri('http://example.com:80');
$this->assertContains($uri->getPort(), [80, null], "If no port is present, but a scheme is present, this method MAY return the standard port for that scheme, but SHOULD return null."); $this->assertContains($uri->getPort(), [80, null], "If no port is present, but a scheme is present, this method MAY return the standard port for that scheme, but SHOULD return null.");
} }
/** /**
* @group authority * @group authority
* @dataProvider authorityProvider * @dataProvider authorityProvider
@ -155,8 +142,7 @@ abstract class AbstractUriTestCase extends TestCase
* If the port component is not set or is the standard port for the current * If the port component is not set or is the standard port for the current
* scheme, it SHOULD NOT be included. * scheme, it SHOULD NOT be included.
*/ */
public function testGetAuthority($scheme, $user, $pass, $host, $port, $authority) public function testGetAuthority($scheme, $user, $pass, $host, $port, $authority) {
{
$uri = $this $uri = $this
->createUri() ->createUri()
->withHost($host) ->withHost($host)
@ -168,8 +154,7 @@ abstract class AbstractUriTestCase extends TestCase
$this->assertSame($authority, $uri->getAuthority()); $this->assertSame($authority, $uri->getAuthority());
} }
public function authorityProvider() public function authorityProvider() {
{
return [ return [
'authority' => [ 'authority' => [
'scheme' => 'http', 'scheme' => 'http',
@ -222,15 +207,13 @@ abstract class AbstractUriTestCase extends TestCase
* any characters. To determine what characters to encode, please refer to * any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.4. * RFC 3986, Sections 2 and 3.4.
*/ */
public function testGetQuery($query, $expected) public function testGetQuery($query, $expected) {
{
$uri = $this->uri->withQuery($query); $uri = $this->uri->withQuery($query);
$this->assertInstanceOf(UriInterface::class, $uri); $this->assertInstanceOf(UriInterface::class, $uri);
$this->assertSame($expected, $uri->getQuery(), 'Query must be normalized according to RFC3986'); $this->assertSame($expected, $uri->getQuery(), 'Query must be normalized according to RFC3986');
} }
public function queryProvider() public function queryProvider() {
{
return [ return [
'normalized query' => ['foo.bar=%7evalue', 'foo.bar=~value'], 'normalized query' => ['foo.bar=%7evalue', 'foo.bar=~value'],
'empty query' => ['', ''], 'empty query' => ['', ''],
@ -247,15 +230,13 @@ abstract class AbstractUriTestCase extends TestCase
* any characters. To determine what characters to encode, please refer to * any characters. To determine what characters to encode, please refer to
* RFC 3986, Sections 2 and 3.5. * RFC 3986, Sections 2 and 3.5.
*/ */
public function testGetFragment($fragment, $expected) public function testGetFragment($fragment, $expected) {
{
$uri = $this->uri->withFragment($fragment); $uri = $this->uri->withFragment($fragment);
$this->assertInstanceOf(UriInterface::class, $uri); $this->assertInstanceOf(UriInterface::class, $uri);
$this->assertSame($expected, $uri->getFragment(), 'Fragment must be normalized according to RFC3986'); $this->assertSame($expected, $uri->getFragment(), 'Fragment must be normalized according to RFC3986');
} }
public function fragmentProvider() public function fragmentProvider() {
{
return [ return [
'URL with full components' => ['fragment', 'fragment'], 'URL with full components' => ['fragment', 'fragment'],
'URL with non-encodable fragment' => ["azAZ0-9/?-._~!$&'()*+,;=:@", "azAZ0-9/?-._~!$&'()*+,;=:@"], 'URL with non-encodable fragment' => ["azAZ0-9/?-._~!$&'()*+,;=:@", "azAZ0-9/?-._~!$&'()*+,;=:@"],
@ -278,8 +259,7 @@ abstract class AbstractUriTestCase extends TestCase
* - If a query is present, it MUST be prefixed by "?". * - If a query is present, it MUST be prefixed by "?".
* - If a fragment is present, it MUST be prefixed by "#". * - If a fragment is present, it MUST be prefixed by "#".
*/ */
public function testToString($scheme, $user, $pass, $host, $port, $path, $query, $fragment, $expected) public function testToString($scheme, $user, $pass, $host, $port, $path, $query, $fragment, $expected) {
{
$uri = $this->createUri() $uri = $this->createUri()
->withHost($host) ->withHost($host)
->withScheme($scheme) ->withScheme($scheme)
@ -295,8 +275,7 @@ abstract class AbstractUriTestCase extends TestCase
'URI string must be normalized according to RFC3986 rules' 'URI string must be normalized according to RFC3986 rules'
); );
} }
public function stringProvider() public function stringProvider() {
{
return [ return [
'URL normalized' => [ 'URL normalized' => [
'scheme' => 'HtTps', 'scheme' => 'HtTps',
@ -307,7 +286,7 @@ abstract class AbstractUriTestCase extends TestCase
'path' => '/%7ejohndoe/%a1/index.php', 'path' => '/%7ejohndoe/%a1/index.php',
'query' => 'foo.bar=%7evalue', 'query' => 'foo.bar=%7evalue',
'fragment' => 'fragment', 'fragment' => 'fragment',
'uri' => 'https://iGoR:rAsMuZeN@master.example.com:443/~johndoe/%A1/index.php?foo.bar=~value#fragment' 'uri' => 'https://iGoR:rAsMuZeN@master.example.com:443/~johndoe/%A1/index.php?foo.bar=~value#fragment',
], ],
'URL without scheme' => [ 'URL without scheme' => [
'scheme' => '', 'scheme' => '',
@ -337,8 +316,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group fragment * @group fragment
*/ */
public function testRemoveFragment() public function testRemoveFragment() {
{
$uri = 'http://example.com/path/to/me'; $uri = 'http://example.com/path/to/me';
$this->assertSame($uri, (string) $this->createUri($uri.'#doc')->withFragment('')); $this->assertSame($uri, (string) $this->createUri($uri.'#doc')->withFragment(''));
} }
@ -346,8 +324,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group query * @group query
*/ */
public function testRemoveQuery() public function testRemoveQuery() {
{
$uri = 'http://example.com/path/to/me'; $uri = 'http://example.com/path/to/me';
$this->assertSame($uri, (string) (string) $this->createUri($uri.'?name=value')->withQuery('')); $this->assertSame($uri, (string) (string) $this->createUri($uri.'?name=value')->withQuery(''));
} }
@ -355,8 +332,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group path * @group path
*/ */
public function testRemovePath() public function testRemovePath() {
{
$uri = 'http://example.com'; $uri = 'http://example.com';
$this->assertContains( $this->assertContains(
(string) $this->createUri($uri.'/path/to/me')->withPath(''), (string) $this->createUri($uri.'/path/to/me')->withPath(''),
@ -367,8 +343,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group port * @group port
*/ */
public function testRemovePort() public function testRemovePort() {
{
$this->assertSame( $this->assertSame(
'http://example.com/path/to/me', 'http://example.com/path/to/me',
(string) $this->createUri('http://example.com:81/path/to/me')->withPort(null) (string) $this->createUri('http://example.com:81/path/to/me')->withPort(null)
@ -378,8 +353,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group userinfo * @group userinfo
*/ */
public function testRemoveUserInfo() public function testRemoveUserInfo() {
{
$this->assertSame( $this->assertSame(
'http://example.com/path/to/me', 'http://example.com/path/to/me',
(string) $this->createUri('http://user:pass@example.com/path/to/me')->withUserInfo('') (string) $this->createUri('http://user:pass@example.com/path/to/me')->withUserInfo('')
@ -389,8 +363,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group scheme * @group scheme
*/ */
public function testRemoveScheme() public function testRemoveScheme() {
{
$this->assertSame( $this->assertSame(
'//example.com/path/to/me', '//example.com/path/to/me',
(string) $this->createUri('http://example.com/path/to/me')->withScheme('') (string) $this->createUri('http://example.com/path/to/me')->withScheme('')
@ -400,8 +373,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group authority * @group authority
*/ */
public function testRemoveAuthority() public function testRemoveAuthority() {
{
$uri = 'http://user:login@example.com:82/path?q=v#doc'; $uri = 'http://user:login@example.com:82/path?q=v#doc';
$uri_with_host = $this->createUri($uri) $uri_with_host = $this->createUri($uri)
@ -418,14 +390,12 @@ abstract class AbstractUriTestCase extends TestCase
* @group scheme * @group scheme
* @dataProvider withSchemeFailedProvider * @dataProvider withSchemeFailedProvider
*/ */
public function testWithSchemeFailed($scheme) public function testWithSchemeFailed($scheme) {
{
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->uri->withScheme($scheme); $this->uri->withScheme($scheme);
} }
public function withSchemeFailedProvider() public function withSchemeFailedProvider() {
{
return [ return [
'invalid char' => ['in,valid'], 'invalid char' => ['in,valid'],
'integer like string' => ['123'], 'integer like string' => ['123'],
@ -436,14 +406,12 @@ abstract class AbstractUriTestCase extends TestCase
* @group host * @group host
* @dataProvider withHostFailedProvider * @dataProvider withHostFailedProvider
*/ */
public function testWithHostFailed($host) public function testWithHostFailed($host) {
{
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->uri->withHost($host); $this->uri->withHost($host);
} }
public function withHostFailedProvider() public function withHostFailedProvider() {
{
return [ return [
'dot in front' => ['.example.com'], 'dot in front' => ['.example.com'],
'hyphen suffix' => ['host.com-'], 'hyphen suffix' => ['host.com-'],
@ -469,8 +437,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group host * @group host
*/ */
public function testModificationFailedWithInvalidHost() public function testModificationFailedWithInvalidHost() {
{
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->createUri('http://example.com')->withHost('?'); $this->createUri('http://example.com')->withHost('?');
} }
@ -479,15 +446,12 @@ abstract class AbstractUriTestCase extends TestCase
* @group uri * @group uri
* @dataProvider invalidURI * @dataProvider invalidURI
*/ */
public function testCreateFromInvalidUrlKO($uri) public function testCreateFromInvalidUrlKO($uri) {
{
$this->expectException(InvalidArgumentException::class); $this->expectException(InvalidArgumentException::class);
$this->createUri($uri); $this->createUri($uri);
} }
public function invalidURI() public function invalidURI() {
{
return [ return [
['http://user@:80'], ['http://user@:80'],
]; ];
@ -496,8 +460,7 @@ abstract class AbstractUriTestCase extends TestCase
/** /**
* @group uri * @group uri
*/ */
public function testEmptyValueDetection() public function testEmptyValueDetection() {
{
$expected = '//0:0@0/0?0#0'; $expected = '//0:0@0/0?0#0';
$this->assertSame($expected, (string) $this->createUri($expected)); $this->assertSame($expected, (string) $this->createUri($expected));
} }
@ -506,8 +469,7 @@ abstract class AbstractUriTestCase extends TestCase
* @group path * @group path
* @group uri * @group uri
*/ */
public function testPathDetection() public function testPathDetection() {
{
$expected = 'foo/bar:'; $expected = 'foo/bar:';
$this->assertSame($expected, $this->createUri($expected)->getPath()); $this->assertSame($expected, $this->createUri($expected)->getPath());
} }

5
vendor-bin/csfixer/composer.json

@ -0,0 +1,5 @@
{
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.16"
}
}

1383
vendor-bin/csfixer/composer.lock

File diff suppressed because it is too large
Loading…
Cancel
Save