Browse Source

Apply house style

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

1
.gitignore

@ -2,3 +2,4 @@
/vendor-bin/*/vendor
/tests/coverage
/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);

12
RoboFile.php

@ -24,7 +24,7 @@ class RoboFile extends \Robo\Tasks {
* ./robo test --testsuite TTRSS --exclude-group slow --testdox
*
* Please see the PHPUnit documentation for available options.
*/
*/
public function test(array $args): Result {
return $this->runTests(escapeshellarg(\PHP_BINARY), "typical", $args);
}
@ -33,7 +33,7 @@ class RoboFile extends \Robo\Tasks {
*
* This includes pedantic tests which may help to identify problems.
* See help for the "test" task for more details.
*/
*/
public function testFull(array $args): Result {
return $this->runTests(escapeshellarg(\PHP_BINARY), "full", $args);
}
@ -42,7 +42,7 @@ class RoboFile extends \Robo\Tasks {
* Runs a quick subset of the test suite
*
* See help for the "test" task for more details.
*/
*/
public function testQuick(array $args): Result {
return $this->runTests(escapeshellarg(\PHP_BINARY), "quick", $args);
}
@ -56,7 +56,7 @@ class RoboFile extends \Robo\Tasks {
* Robo first tries to use pcov and will fall back first to xdebug then
* phpdbg. Neither pcov nor xdebug need to be enabled to be used; they
* only need to be present in the extension load path to be used.
*/
*/
public function coverage(array $args): Result {
// run tests with code coverage reporting enabled
$exec = $this->findCoverageEngine();
@ -71,7 +71,7 @@ class RoboFile extends \Robo\Tasks {
* run all tests which may cover code.
*
* See also help for the "coverage" task for more details.
*/
*/
public function coverageFull(array $args): Result {
// run tests with code coverage reporting enabled
$exec = $this->findCoverageEngine();
@ -121,7 +121,7 @@ class RoboFile extends \Robo\Tasks {
return $all ? ">$hole 2>&1" : "2>$hole";
}
protected function runTests(string $executor, string $set, array $args) : Result {
protected function runTests(string $executor, string $set, array $args): Result {
switch ($set) {
case "typical":
$set = ["--exclude-group", "optional"];

2
lib/Category/Category.php

@ -9,7 +9,7 @@ namespace JKingWeb\Lax\Category;
class Category {
public $name = "";
public $label = "";
public $domain = "";
public $domain = "";
public function __toString() {
return strlen(strlen((string) $this->label)) ? $this->label : $this->name;

6
lib/Category/Collection.php

@ -8,10 +8,10 @@ namespace JKingWeb\Lax\Category;
class Collection extends \JKingWeb\Lax\Collection {
protected static $ranks = [
'webmaster' => 10,
'editor' => 20,
'webmaster' => 10,
'editor' => 20,
'contributor' => 30,
'author' => 40,
'author' => 40,
];
/** Returns the collection formatted as an array of strings

5
lib/Collection.php

@ -7,7 +7,6 @@ declare(strict_types=1);
namespace JKingWeb\Lax;
abstract class Collection implements \IteratorAggregate, \ArrayAccess, \Countable, \JsonSerializable {
protected $data = [];
/** Implementation for IteratorAggregate */
@ -52,7 +51,7 @@ abstract class Collection implements \IteratorAggregate, \ArrayAccess, \Countabl
/** Merges one or more other collections' items into this one
*
* The returned collection is the original instance, modified
*/
*/
public function merge(Collection ...$coll): self {
foreach ($coll as $c) {
foreach ($c as $p) {
@ -69,7 +68,7 @@ abstract class Collection implements \IteratorAggregate, \ArrayAccess, \Countabl
* $axis is the property of each collection member which value is to be checked against the terms
*
* $inclusive specified whether the terms are to included in (true) or excluded from (false) the result
*/
*/
protected function filter(array $terms, string $axis, bool $inclusive): self {
$out = new static;
foreach ($this as $item) {

2
lib/Date.php

@ -7,7 +7,7 @@ declare(strict_types=1);
namespace JKingWeb\Lax;
class Date extends \DateTimeImmutable implements \JsonSerializable {
static public $supportedFormats = [
public static $supportedFormats = [
// RFC 3339 formats
'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
"notJSONType" => [0x1111, "Document Content-Type is not either that of JSON Feed or generic 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) {
@ -19,7 +19,7 @@ abstract class Exception extends \Exception {
if (!$data) {
throw new \Exception("Exception symbol \"$symbol\" does not exist");
}
list($code, $msg) = $data;
[$code, $msg] = $data;
parent::__construct($msg, $code, $e);
}
}

3
lib/Parser/Construct.php

@ -42,7 +42,8 @@ trait Construct {
$domain = $match[2];
// 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)
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 false;

6
lib/Parser/JSON/Entry.php

@ -69,7 +69,7 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
$exp = (int) $id[1];
$mul = $exp > -1;
$exp = abs($exp);
list($int, $dec) = explode(".", $id[0]);
[$int, $dec] = explode(".", $id[0]);
$dec = strlen($dec) ? str_split($dec, 1) : [];
$int = str_split($int, 1);
if ($int[0] === "-") {
@ -89,7 +89,7 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
array_unshift($dec, "0");
}
}
return ($neg ? "-" : "") . ($int ? implode("", $int) : "0") . ($dec ? ("." . rtrim(implode("", $dec), "0")) : "");
return ($neg ? "-" : "").($int ? implode("", $int) : "0").($dec ? (".".rtrim(implode("", $dec), "0")) : "");
}
}
} else {
@ -156,7 +156,7 @@ class Entry implements \JKingWeb\Lax\Parser\Entry {
$out[] = $m;
}
// handle other attachments
foreach ($this->fetchMember("attachments", "array") ?? [] as $attachment) {
foreach ($this->fetchMember("attachments", "array") ?? [] as $attachment) {
$url = $this->fetchUrl("url", $attachment);
if ($url) {
$m = new Enclosure;

7
lib/Parser/JSON/Feed.php

@ -8,7 +8,6 @@ namespace JKingWeb\Lax\Parser\JSON;
use JKingWeb\Lax\Text;
use JKingWeb\Lax\Date;
use JKingWeb\Lax\Entry;
use JKingWeb\Lax\Feed as FeedStruct;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Category\Collection as CategoryCollection;
@ -84,7 +83,7 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
/** {@inheritdoc}
*
* For JSON feeds this is always the feed URL specified in the feed
*/
*/
public function getId(): ?string {
return $this->fetchMember("feed_url", "str");
}
@ -108,7 +107,7 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
/** {@inheritdoc}
*
* JSON feeds themselves don't have dates, so this always returns null
*/
*/
public function getDateModified(): ?Date {
return null;
}
@ -120,7 +119,7 @@ class Feed implements \JKingWeb\Lax\Parser\Feed {
/** {@inheritdoc}
*
* JSON Feed does not have categories at the feed level, so this always returns and empty collection
*/
*/
public function getCategories(): CategoryCollection {
return new CategoryCollection;
}

18
lib/Parser/XML/Construct.php

@ -15,7 +15,7 @@ trait Construct {
use \JKingWeb\Lax\Parser\Construct;
/** @var \DOMDocument */
public $document;
protected $document;
/** @var \DOMXPath */
protected $xpath;
/** @var \DOMElement */
@ -24,7 +24,7 @@ trait Construct {
/** Retrieves an element node based on an XPath query */
protected function fetchElement(string $query, \DOMNode $context = null) {
$node = @$this->xpath->query("(".$query.")[1]", $context ?? $this->subject);
if ($node===false) {
if ($node === false) {
throw new \Exception("Invalid XPath query: $query"); // @codeCoverageIgnore
}
return ($node->length) ? $node->item(0) : null;
@ -55,12 +55,12 @@ trait Construct {
protected function fetchStringAtom(string $query, bool $html = false): ?Text {
$node = $this->fetchElement($query);
if ($node) {
if (!$node->hasAttribute("type") || $node->getAttribute("type")=="text") {
if (!$node->hasAttribute("type") || $node->getAttribute("type") == "text") {
return $html ? htmlspecialchars($this->trimText($node->textContent), \ENT_QUOTES | \ENT_HTML5) : $this->trimText($node->textContent);
} elseif ($node->getAttribute("type")=="xhtml") {
} elseif ($node->getAttribute("type") == "xhtml") {
$node = $node->getElementsByTagNameNS(self::NS['xhtml'], "div")->item(0);
return $node ? $this->sanitizeElement($node, $html) : null;
} elseif ($node->getAttribute("type")=="html") {
} elseif ($node->getAttribute("type") == "html") {
return $this->sanitizeString($node->textContent, $html);
} else {
return null;
@ -83,12 +83,12 @@ trait Construct {
*/
protected function fetchAtomRelations(string $rel = ""): \DOMNodeList {
// FIXME: The XPath evaluation will fail if the relation contains an apostrophe. This is a known and difficult-to-overcome limitation of XPath 1.0 which I consider not worth the effort to address at this time
if ($rel=="" || $rel=="alternate" || $rel=="http://www.iana.org/assignments/relation/alternate") {
if ($rel == "" || $rel == "alternate" || $rel == "http://www.iana.org/assignments/relation/alternate") {
$cond = "not(@rel) or @rel='' or @rel='alternate' or @rel='http://www.iana.org/assignments/relation/alternate'";
} elseif (strpos($rel, ":")===false) {
} elseif (strpos($rel, ":") === false) {
// FIXME: Checking only for a colon in a link relation is a hack that does not strictly follow IRI rules, but it's adequate for our needs
$cond = "@rel='$rel' or @rel='http://www.iana.org/assignments/relation/$rel'";
} elseif (strlen($rel) > 41 && strpos($rel, "http://www.iana.org/assignments/relation/")===0) {
} elseif (strlen($rel) > 41 && strpos($rel, "http://www.iana.org/assignments/relation/") === 0) {
$rel = substr($rel, 41);
$cond = "@rel='$rel' or @rel='http://www.iana.org/assignments/relation/$rel'";
} else {
@ -162,7 +162,7 @@ trait Construct {
* This automatically performs xml:base and HTML <base> resolution
*
* Specifying the empty string for $attr results in the element content being used as a URL
*/
*/
protected function resolveNodeUrl(\DOMElement $node = null, string $attr = "", string $ns = null): string {
$base = $node->baseURI;
$url = strlen($attr) ? $node->getAttributeNS($ns, $attr) : $this->trimText($node->textContent);

18
lib/Parser/XML/Feed.php

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

8
lib/Parser/XML/Primitives/Construct.php

@ -92,7 +92,7 @@ trait Construct {
/** Primitive to fetch Dublin Core feed/entry categories
*
* Dublin Core doesn't have an obvious category type, so we use 'subject' as a nearest approximation
*/
*/
protected function getCategoriesDC(): ?CategoryCollection {
$out = new CategoryCollection;
foreach ($this->fetchStringMulti("dc:subject") ?? [] as $text) {
@ -126,7 +126,7 @@ trait Construct {
/** Primitive to fetch an RSS feed/entry identifier
*
* Using RSS' <guid> for feed identifiers is non-standard, but harmless
*/
*/
protected function getIdRss2(): ?string {
return $this->fetchString("guid");
}
@ -169,7 +169,7 @@ trait Construct {
/** Primitive to fetch a collection of authors associated with a podcast/episode
*
* The collection only ever contains the first author found: podcasts implicitly have only one author
*/
*/
protected function getAuthorsPod(): ?PersonCollection {
$out = new PersonCollection;
$p = new Person;
@ -185,7 +185,7 @@ trait Construct {
/** Primitive to fetch a collection of webmasters associated with a podcast
*
* The collection only ever contains the first webmaster found: podcasts implicitly have only one webmaster
*/
*/
protected function getWebmastersPod(): ?PersonCollection {
$out = new PersonCollection;
$node = $this->fetchElement("gplay:owner|apple:owner");

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

@ -6,14 +6,13 @@
declare(strict_types=1);
namespace JKingWeb\Lax\Parser\XML\Primitives;
use JKingWeb\Lax\Person\Collection as PersonCollection;
use JKingWeb\Lax\Parser\XML\XPath;
trait Entry {
/** Primitive to fetch a collection of authors associated with an Atom entry
*
* This differs from feeds in that an entry's <source> element (which possibly contains metadata for the source feed) is checked for authors if the entry itself has none
*/
*/
protected function getAuthorsAtom() {
return $this->fetchPeopleAtom("atom:author", "author") ?? $this->fetchPeopleAtom("atom:source[1]/atom:author", "author");
}
@ -22,7 +21,7 @@ trait Entry {
protected function getUrlRss1() {
// XPath doesn't seem to like the query we'd need for this, so it must be done the hard way.
$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']);
} else {
return null;

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

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

6
lib/Person/Collection.php

@ -9,9 +9,9 @@ namespace JKingWeb\Lax\Person;
class Collection extends \JKingWeb\Lax\Collection {
protected static $ranks = [
'contributor' => -10,
'webmaster' => 10,
'editor' => 20,
'author' => 30,
'webmaster' => 10,
'editor' => 20,
'author' => 30,
];
/** Returns the primary person of the collection

2
lib/Person/Person.php

@ -9,7 +9,7 @@ namespace JKingWeb\Lax\Person;
class Person {
public $name = null;
public $mail = null;
public $url = null;
public $url = null;
public $role = null;
public $avatar = null;

6
lib/Sanitizer.php

@ -216,13 +216,13 @@ class Sanitizer {
*/
public function processDocument(\DOMDocument $doc, string $url): \DOMDocument {
// 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
foreach ((new \DOMXPath($doc))->query("//*") as $node) {
// 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;
} elseif ($node->namespaceURI=="") {
} elseif ($node->namespaceURI === "") {
$qName = $node->tagName;
} elseif (isset($this->namespaces[$node->namespaceURI])) {
$qName = $this->namespaces[$node->namespaceURI].":".$node->tagName;

2
lib/Url.php

@ -266,7 +266,7 @@ PCRE;
$this->fragment = $fragment;
}
}
} elseif(strlen($path)) {
} elseif (strlen($path)) {
if ($this->path[0] !== "/") {
if ($path[-1] === "/") {
$this->path = $path.$this->path;

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\Parser as YamlParser;
/**
* @covers JKingWeb\Lax\Parser\Construct<extended>
* @covers JKingWeb\Lax\Parser\JSON\Feed<extended>

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

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