Skip to content

chore: add cs-fixer v3 #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
matrix:
php-versions: ['7.2', '7.3', '7.4', '8.0', '8.1', '8.2', '8.3']
coverage: ['pcov']
code-style: ['no']
code-style: ['yes']
code-analysis: ['no']
include:
- php-versions: '7.1'
Expand All @@ -23,7 +23,7 @@ jobs:
code-analysis: 'yes'
- php-versions: '8.4'
coverage: 'pcov'
code-style: 'no'
code-style: 'yes'
code-analysis: 'yes'
steps:
- name: Checkout
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
tests/cov
tests/.phpunit.result.cache
.php_cs.cache
.php-cs-fixer.cache
17 changes: 17 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

$finder = PhpCsFixer\Finder::create()
->exclude('vendor')
->in(__DIR__);

$config = new PhpCsFixer\Config();
$config->setRules([
'@PSR1' => true,
'@Symfony' => true,
'nullable_type_declaration' => [
'syntax' => 'question_mark',
],
'nullable_type_declaration_for_default_null_value' => true,
]);
$config->setFinder($finder);
return $config;
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
}
},
"require-dev": {
"friendsofphp/php-cs-fixer": "~2.17.1",
"friendsofphp/php-cs-fixer": "~2.17.1||3.60",
"phpstan/phpstan": "^0.12",
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.6"
},
Expand All @@ -53,7 +53,7 @@
"phpstan analyse lib tests"
],
"cs-fixer": [
"php-cs-fixer fix"
"PHP_CS_FIXER_IGNORE_ENV=true php-cs-fixer fix"
],
"phpunit": [
"phpunit --configuration tests/phpunit.xml"
Expand Down
2 changes: 0 additions & 2 deletions lib/Deserializer/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,6 @@ function mixedContent(Reader $reader): array
*
* You can use, e.g., a named constructor (factory method) to create an object using
* this function.
*
* @return mixed
*/
function functionCaller(Reader $reader, callable $func, string $namespace)
{
Expand Down
4 changes: 0 additions & 4 deletions lib/Element/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ class Base implements Xml\Element
{
/**
* PHP value to serialize.
*
* @var mixed
*/
protected $value;

Expand Down Expand Up @@ -72,8 +70,6 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
{
Expand Down
2 changes: 0 additions & 2 deletions lib/Element/Elements.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
{
Expand Down
2 changes: 0 additions & 2 deletions lib/Element/KeyValue.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,6 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
{
Expand Down
2 changes: 0 additions & 2 deletions lib/Element/Uri.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
{
Expand Down
2 changes: 0 additions & 2 deletions lib/Element/XmlFragment.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ public function xmlSerialize(Writer $writer)
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader)
{
Expand Down
6 changes: 2 additions & 4 deletions lib/LibXMLException.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace Sabre\Xml;

use LibXMLError;
use Throwable;

/**
* This exception is thrown when the Reader runs into a parsing error.
Expand All @@ -30,10 +29,9 @@ class LibXMLException extends ParseException
*
* You should pass a list of LibXMLError objects in its constructor.
*
* @param LibXMLError[] $errors
* @param Throwable $previousException
* @param \LibXMLError[] $errors
*/
public function __construct(array $errors, int $code = 0, ?Throwable $previousException = null)
public function __construct(array $errors, int $code = 0, ?\Throwable $previousException = null)
{
$this->errors = $errors;
parent::__construct($errors[0]->message.' on line '.$errors[0]->line.', column '.$errors[0]->column, $code, $previousException);
Expand Down
2 changes: 1 addition & 1 deletion lib/ParseException.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class ParseException extends Exception
class ParseException extends \Exception
{
}
4 changes: 2 additions & 2 deletions lib/Reader.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Reader extends XMLReader
class Reader extends \XMLReader
{
use ContextStackTrait;

Expand Down Expand Up @@ -205,7 +205,7 @@ public function readText(): string
$previousDepth = $this->depth;

while ($this->read() && $this->depth != $previousDepth) {
if (in_array($this->nodeType, [XMLReader::TEXT, XMLReader::CDATA, XMLReader::WHITESPACE])) {
if (in_array($this->nodeType, [\XMLReader::TEXT, \XMLReader::CDATA, \XMLReader::WHITESPACE])) {
$result .= $this->value;
}
}
Expand Down
7 changes: 3 additions & 4 deletions lib/Serializer/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

namespace Sabre\Xml\Serializer;

use InvalidArgumentException;
use Sabre\Xml\Writer;
use Sabre\Xml\XmlSerializable;

Expand Down Expand Up @@ -197,12 +196,12 @@ function standardSerializer(Writer $writer, $value)
$writer->write($item);
$writer->endElement();
} else {
throw new InvalidArgumentException('The writer does not know how to serialize arrays with keys of type: '.gettype($name));
throw new \InvalidArgumentException('The writer does not know how to serialize arrays with keys of type: '.gettype($name));
}
}
} elseif (is_object($value)) {
throw new InvalidArgumentException('The writer cannot serialize objects of class: '.get_class($value));
throw new \InvalidArgumentException('The writer cannot serialize objects of class: '.get_class($value));
} elseif (!is_null($value)) {
throw new InvalidArgumentException('The writer cannot serialize values of type: '.gettype($value));
throw new \InvalidArgumentException('The writer cannot serialize values of type: '.gettype($value));
}
}
8 changes: 4 additions & 4 deletions lib/Service.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ public function getWriter(): Writer
*
* @param string|resource $input
*
* @throws ParseException
*
* @return array|object|string
*
* @throws ParseException
*/
public function parse($input, ?string $contextUri = null, ?string &$rootElementName = null)
{
Expand Down Expand Up @@ -149,9 +149,9 @@ public function parse($input, ?string $contextUri = null, ?string &$rootElementN
* @param string|string[] $rootElementName
* @param string|resource $input
*
* @throws ParseException
*
* @return array|object|string
*
* @throws ParseException
*/
public function expect($rootElementName, $input, ?string $contextUri = null)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/Version.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class Version
/**
* Full version number.
*/
const VERSION = '2.2.9';
public const VERSION = '2.2.9';
}
6 changes: 2 additions & 4 deletions lib/Writer.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
* @author Evert Pot (http://evertpot.com/)
* @license http://sabre.io/license/ Modified BSD License
*/
class Writer extends XMLWriter
class Writer extends \XMLWriter
{
use ContextStackTrait;

Expand Down Expand Up @@ -93,8 +93,6 @@ class Writer extends XMLWriter
* ]
* ]
* ]
*
* @param mixed $value
*/
public function write($value)
{
Expand Down Expand Up @@ -151,7 +149,7 @@ public function startElement($name): bool

if (!$this->namespacesWritten) {
foreach ($this->namespaceMap as $namespace => $prefix) {
$this->writeAttribute(($prefix ? 'xmlns:'.$prefix : 'xmlns'), $namespace);
$this->writeAttribute($prefix ? 'xmlns:'.$prefix : 'xmlns', $namespace);
}
$this->namespacesWritten = true;
}
Expand Down
2 changes: 0 additions & 2 deletions lib/XmlDeserializable.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ interface XmlDeserializable
*
* $reader->parseInnerTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Reader $reader);
}
2 changes: 0 additions & 2 deletions tests/Sabre/Xml/Element/Eater.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
{
Expand Down
2 changes: 0 additions & 2 deletions tests/Sabre/Xml/Element/Mock.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@ public function xmlSerialize(Xml\Writer $writer)
*
* $reader->parseSubTree() will parse the entire sub-tree, and advance to
* the next element.
*
* @return mixed
*/
public static function xmlDeserialize(Xml\Reader $reader)
{
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/Xml/Element/XmlFragmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public function testSerialize($expectedFallback, $input, $expected = null)
];
$writer->openMemory();
$writer->startDocument('1.0');
//$writer->setIndent(true);
// $writer->setIndent(true);
$writer->write([
'{http://sabredav.org/ns}root' => [
'{http://sabredav.org/ns}fragment' => new XmlFragment($input),
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/Xml/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public function testMappedElementBadClass()

$reader = new Reader();
$reader->elementMap = [
'{http://sabredav.org/ns}elem1' => new \StdClass(),
'{http://sabredav.org/ns}elem1' => new \stdClass(),
];
$reader->xml($input);

Expand Down
6 changes: 3 additions & 3 deletions tests/Sabre/Xml/ServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public function testMapValueObject()
XML;

$ns = 'http://sabredav.org/ns';
$orderService = new \Sabre\Xml\Service();
$orderService = new Service();
$orderService->mapValueObject('{'.$ns.'}order', 'Sabre\Xml\Order');
$orderService->mapValueObject('{'.$ns.'}status', 'Sabre\Xml\OrderStatus');
$orderService->namespaceMap[$ns] = null;
Expand Down Expand Up @@ -317,7 +317,7 @@ public function testMapValueObjectArrayProperty()
XML;

$ns = 'http://sabredav.org/ns';
$orderService = new \Sabre\Xml\Service();
$orderService = new Service();
$orderService->mapValueObject('{'.$ns.'}order', 'Sabre\Xml\Order');
$orderService->mapValueObject('{'.$ns.'}status', 'Sabre\Xml\OrderStatus');
$orderService->namespaceMap[$ns] = null;
Expand All @@ -342,7 +342,7 @@ public function testWriteVoNotFound()
{
$this->expectException(\InvalidArgumentException::class);
$service = new Service();
$service->writeValueObject(new \StdClass());
$service->writeValueObject(new \stdClass());
}

public function testParseClarkNotation()
Expand Down
2 changes: 1 addition & 1 deletion tests/Sabre/Xml/WriterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ public function testWriteElementComplex()
public function testWriteBadObject()
{
$this->expectException(\InvalidArgumentException::class);
$this->writer->write(new \StdClass());
$this->writer->write(new \stdClass());
}

public function testStartElementSimple()
Expand Down
Loading