From 4eb3d2db7f004c22276e59aac05450e16e4f158e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 19 Oct 2018 23:08:28 +0200 Subject: [PATCH 1/2] Add phpstan to travis --- .travis.yml | 27 ++++++++++++++++++++------- phpstan.neon | 3 +++ 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 phpstan.neon diff --git a/.travis.yml b/.travis.yml index adab7895e..2619562ab 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,19 +8,32 @@ php: - 7.2 - 7.3 +env: + global: + - RUN_PHPSTAN="FALSE" + +matrix: + include: + - name: 'PHPStan' + php: 7.2 + env: RUN_PHPSTAN="TRUE" + fast_finish: true + allow_failures: + - php: 5.5 + +install: + - if [ $RUN_PHPSTAN == "TRUE" ]; then wget https://github.com/phpstan/phpstan/releases/download/0.10.3/phpstan.phar; fi + before_script: -- composer install + - composer install script: - - ./bin/phpunit --configuration tests/phpunit.xml --coverage-clover=coverage.xml + - if [ $RUN_PHPSTAN == "FALSE" ]; then ./bin/phpunit --configuration tests/phpunit.xml --coverage-clover=coverage.xml; fi + - if [ $RUN_PHPSTAN == "TRUE" ]; then php phpstan.phar analyse -c phpstan.neon lib; fi after_success: -- bash <(curl -s https://codecov.io/bash) + - bash <(curl -s https://codecov.io/bash) cache: directories: - $HOME/.composer/cache - -matrix: - allow_failures: - - php: 5.5 diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 000000000..e50c5be6e --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,3 @@ +parameters: + level: 0 + bootstrap: %currentWorkingDirectory%/vendor/autoload.php From 9fed1c4f28857244560d0dab7f4fb23038df883b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Fri, 19 Oct 2018 23:24:31 +0200 Subject: [PATCH 2/2] Fix phpstan level 0 --- lib/Document.php | 11 +++++++---- lib/Parser/Json.php | 3 ++- lib/Parser/MimeDir.php | 3 ++- lib/Parser/XML.php | 4 ++-- lib/Property/ICalendar/DateTime.php | 4 ++-- lib/Splitter/ICalendar.php | 2 +- lib/Splitter/SplitterInterface.php | 2 +- lib/Splitter/VCard.php | 2 +- lib/TimeZoneUtil.php | 2 +- lib/Writer.php | 4 ++-- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/lib/Document.php b/lib/Document.php index 2fb0451ae..0cb2e0978 100644 --- a/lib/Document.php +++ b/lib/Document.php @@ -95,13 +95,16 @@ abstract class Document extends Component public function __construct() { $args = func_get_args(); + $name = static::$defaultName; if (0 === count($args) || is_array($args[0])) { - array_unshift($args, $this, static::$defaultName); - call_user_func_array(['parent', '__construct'], $args); + $children = isset($args[0]) ? $args[0] : []; + $defaults = isset($args[1]) ? $args[1] : true; } else { - array_unshift($args, $this); - call_user_func_array(['parent', '__construct'], $args); + $name = $args[0]; + $children = isset($args[1]) ? $args[1] : []; + $defaults = isset($args[2]) ? $args[2] : true; } + parent::__construct($this, $name, $children, $defaults); } /** diff --git a/lib/Parser/Json.php b/lib/Parser/Json.php index 2062f8614..3fd307e97 100644 --- a/lib/Parser/Json.php +++ b/lib/Parser/Json.php @@ -4,6 +4,7 @@ use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCard; +use Sabre\VObject\Document; use Sabre\VObject\EofException; use Sabre\VObject\ParseException; @@ -43,7 +44,7 @@ class Json extends Parser * @param resource|string|array|null $input * @param int $options * - * @return Sabre\VObject\Document + * @return \Sabre\VObject\Document */ public function parse($input = null, $options = 0) { diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php index 50c5e55b8..d98225b59 100644 --- a/lib/Parser/MimeDir.php +++ b/lib/Parser/MimeDir.php @@ -7,6 +7,7 @@ use Sabre\VObject\Component\VCard; use Sabre\VObject\Document; use Sabre\VObject\EofException; +use Sabre\VObject\Node; use Sabre\VObject\ParseException; /** @@ -72,7 +73,7 @@ class MimeDir extends Parser * @param string|resource|null $input * @param int $options * - * @return Sabre\VObject\Document + * @return \Sabre\VObject\Document */ public function parse($input = null, $options = 0) { diff --git a/lib/Parser/XML.php b/lib/Parser/XML.php index 0a6c7b637..90f262d9e 100644 --- a/lib/Parser/XML.php +++ b/lib/Parser/XML.php @@ -40,7 +40,7 @@ class XML extends Parser /** * Document, root component. * - * @var Sabre\VObject\Document + * @var \Sabre\VObject\Document */ protected $root; @@ -69,7 +69,7 @@ public function __construct($input = null, $options = 0) * * @throws \Exception * - * @return Sabre\VObject\Document + * @return \Sabre\VObject\Document */ public function parse($input = null, $options = 0) { diff --git a/lib/Property/ICalendar/DateTime.php b/lib/Property/ICalendar/DateTime.php index 5db941c1e..7eb3e0bb7 100644 --- a/lib/Property/ICalendar/DateTime.php +++ b/lib/Property/ICalendar/DateTime.php @@ -131,7 +131,7 @@ public function isFloating() * * @param DateTimeZone $timeZone * - * @return DateTimeImmutable + * @return \DateTimeImmutable */ public function getDateTime(DateTimeZone $timeZone = null) { @@ -152,7 +152,7 @@ public function getDateTime(DateTimeZone $timeZone = null) * * @param DateTimeZone $timeZone * - * @return DateTimeImmutable[] + * @return \DateTimeImmutable[] * @return \DateTime[] */ public function getDateTimes(DateTimeZone $timeZone = null) diff --git a/lib/Splitter/ICalendar.php b/lib/Splitter/ICalendar.php index 0b2f8c180..79f7207fd 100644 --- a/lib/Splitter/ICalendar.php +++ b/lib/Splitter/ICalendar.php @@ -83,7 +83,7 @@ public function __construct($input, $options = 0) * * When the end is reached, null will be returned. * - * @return Sabre\VObject\Component|null + * @return \Sabre\VObject\Component|null */ public function getNext() { diff --git a/lib/Splitter/SplitterInterface.php b/lib/Splitter/SplitterInterface.php index f15c5e461..a2c43d662 100644 --- a/lib/Splitter/SplitterInterface.php +++ b/lib/Splitter/SplitterInterface.php @@ -32,7 +32,7 @@ public function __construct($input); * * When the end is reached, null will be returned. * - * @return Sabre\VObject\Component|null + * @return \Sabre\VObject\Component|null */ public function getNext(); } diff --git a/lib/Splitter/VCard.php b/lib/Splitter/VCard.php index 953be6be2..02509c6c3 100644 --- a/lib/Splitter/VCard.php +++ b/lib/Splitter/VCard.php @@ -55,7 +55,7 @@ public function __construct($input, $options = 0) * * When the end is reached, null will be returned. * - * @return Sabre\VObject\Component|null + * @return \Sabre\VObject\Component|null */ public function getNext() { diff --git a/lib/TimeZoneUtil.php b/lib/TimeZoneUtil.php index 9d2d34670..5b1a775c2 100644 --- a/lib/TimeZoneUtil.php +++ b/lib/TimeZoneUtil.php @@ -120,7 +120,7 @@ class TimeZoneUtil * @param string $tzid * @param Sabre\VObject\Component $vcalendar * - * @return DateTimeZone + * @return \DateTimeZone */ public static function getTimeZone($tzid, Component $vcalendar = null, $failIfUncertain = false) { diff --git a/lib/Writer.php b/lib/Writer.php index b589b4cc4..c70a6ae4d 100644 --- a/lib/Writer.php +++ b/lib/Writer.php @@ -58,10 +58,10 @@ public static function writeXml(Component $component) if ($component instanceof Component\VCalendar) { $writer->startElement('icalendar'); - $writer->writeAttribute('xmlns', Parser\Xml::XCAL_NAMESPACE); + $writer->writeAttribute('xmlns', Parser\XML::XCAL_NAMESPACE); } else { $writer->startElement('vcards'); - $writer->writeAttribute('xmlns', Parser\Xml::XCARD_NAMESPACE); + $writer->writeAttribute('xmlns', Parser\XML::XCARD_NAMESPACE); } $component->xmlSerialize($writer);