diff --git a/.gitattributes b/.gitattributes index f95a950f7..602c23776 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,4 +1,5 @@ -/tests export-ignore +/.github/ export-ignore +/tests/ export-ignore /.gitattributes export-ignore /.gitignore export-ignore /.php_cs.dist export-ignore diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 000000000..0515d2344 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,15 @@ +# To get started with Dependabot version updates, you'll need to specify which +# package ecosystems to update and where the package manifests are located. +# Please see the documentation for all configuration options: +# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates + +version: 2 +updates: + - package-ecosystem: "composer" + directory: "/" + schedule: + interval: "monthly" + - package-ecosystem: "github-actions" # See documentation for possible values + directory: "/" # Location of package manifests + schedule: + interval: "monthly" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..3d665e841 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,63 @@ +name: continuous-integration +on: + push: + branches: + - master + - release/* + pull_request: +jobs: + unit-testing: + name: PHPUnit (PHP ${{ matrix.php-versions }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + php-versions: ['7.4', '8.0', '8.1', '8.2', '8.3'] + coverage: ['pcov'] + code-analysis: ['no'] + include: + - php-versions: '7.4' + coverage: 'none' + code-analysis: 'yes' + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Setup PHP, with composer and extensions + uses: shivammathur/setup-php@v2 #https://github.com/shivammathur/setup-php + with: + php-version: ${{ matrix.php-versions }} + extensions: mbstring, dom, fileinfo, mysql, redis, opcache + coverage: ${{ matrix.coverage }} + tools: composer + + - name: Get composer cache directory + id: composer-cache + run: echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT + + - name: Cache composer dependencies + uses: actions/cache@v3 + with: + path: ${{ steps.composer-cache.outputs.dir }} + # Use composer.json for key, if composer.lock is not committed. + # key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }} + restore-keys: ${{ runner.os }}-composer- + + - name: Install composer dependencies + run: composer install --no-progress --prefer-dist --optimize-autoloader + + - name: Code Analysis (PHP CS-Fixer) + if: matrix.code-analysis == 'yes' + run: php vendor/bin/php-cs-fixer fix --dry-run --diff + + - name: Code Analysis (PHPStan) + if: matrix.code-analysis == 'yes' + run: composer phpstan + + - name: Test with phpunit + run: vendor/bin/phpunit --configuration tests/phpunit.xml --coverage-clover clover.xml + + - name: Code Coverage + uses: codecov/codecov-action@v3 + if: matrix.coverage != 'none' diff --git a/.gitignore b/.gitignore index 82b7dad3f..d6e0a1d04 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,4 @@ tests/temp tests/.phpunit.result.cache # Development stuff -.php_cs.cache +.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 000000000..e981862b7 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,15 @@ +getFinder() + ->exclude('vendor') + ->in(__DIR__) + ->append([ + __FILE__, + ]); +$config->setRules([ + '@PSR1' => true, + '@Symfony' => true, +]); + +return $config; diff --git a/.php_cs.dist b/.php_cs.dist deleted file mode 100644 index 4aaf1d90f..000000000 --- a/.php_cs.dist +++ /dev/null @@ -1,12 +0,0 @@ -getFinder() - ->exclude('vendor') - ->in(__DIR__); -$config->setRules([ - '@PSR1' => true, - '@Symfony' => true -]); - -return $config; diff --git a/CHANGELOG.md b/CHANGELOG.md index a14c99ab5..22ca89327 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -153,6 +153,121 @@ ChangeLog * #3 Add daily occurrences to nextMonth and NextYear * #4 Enhance fast forward speed if no count value has been given +4.5.2 (2023-01-20) +------------------ + +* #603: Support sabre/xml v4 (@gharlan) + +4.5.1 (2022-10-09) +------------------ + +* #597: Remove utf8_encode to easily support PHP 8.2 (@phil-davis) + +4.5.0 (2022-08-17) +------------------ + +* #579: Update .gitattributes (@cedric-anne) +* #561: PHP 8.1 deprecated support for null values in its APIs (@mstilkerich) +* #571: Fully ignore invalid lines (@heiglandreas) +* #564: Fix infinite loop caused by yearly with bySetPos (@liurxliu) +* #567: Endless loop problem in RRuleIterator::nextDaily (@KristofferFM) +* #466: Add support for MEMBER in a VCard (@sash04ek) +* #559: Handle Vobjects without closing tag (@sash04ek) +* #582: Fix bug in by year day (@KAYLukas) + +4.4.3 (2022-07-15) +------------------ + +* #577: Ignore multiple same parameter-values (@heiglandreas) + +4.4.2 (2022-06-24) +------------------ + +* #565: lowercase mailto:-addresses in getNormalizedValue() (@pk1234) +* #568: Add NICKNAME fallback for VCards without FNs (@Evengard) +* #573: Component/select: Before uppercasing $child->group, make sure it isn't null (@algernon) +* #575: Fix encoding detection on PHP 8.1 (@come-nc) + +4.4.1 (2021-12-07) +------------------ + + #557: Fix Iterator method signatures and avoid passing null as separator for implode (PHP 8.1 support) (@come-nc) + +4.4.0 (2021-11-15) +------------------ + + #548: Allow easier extension of the timezone guessing (@heiglandreas) + +4.3.8 (2021-11-14) +------------------ + +* #538: fix EventIterator returns wrong end endTime (@floerke) +* #541: Reordering of the attendees is not a significant change (@floerke) +* #543: Reordering of vevent is not a significant change (@floerke) + +4.3.7 (2021-11-04) +------------------ + +* #551: version bump that was missed in 4.3.6 (@phil-davis) + +4.3.6 (2021-11-04) +------------------ + +* #544: Fix deprecated usages and return types on PHP 8.1 (@cedric-anne) + +4.3.5 (2021-02-12) +------------------ + +* #523: Fix setting properties with group assignment (@mstilkerich) +* #532: Make use of until parameter in nextMonthly function (@jaircuevajunior) + +4.3.4 (2021-02-04) +------------------ + +* #529: Reassign modified date in yearly rrule (@laoneo) +* #525: Add .gitattributes to reduce package size (@fezfez) + +4.3.3 (2020-11-09) +------------------ + +* #519: Remove US/Pacific-New obsolete timezone (@phil-davis) + +4.3.2 (2020-10-03) +------------------ + +* #513: Added Support for PHP 8.0 (@phil-davis) + +4.3.1 (2020-07-13) +------------------ + +* #510: Fix an incomplete phpdoc type annotation (@mstilkerich) +* #505: Refactor unit test code for phpunit9 (@phil-davis) +* #500: Standardize CI (@phil-davis) +* #496: CI tooling changes (@JeroenVanOort) + +4.3.0 (2020-01-31) +------------------ + +* Added support for PHP 7.4, dropped support for PHP 7.0 (@phil-davis) +* #487: Added phpstan coverage, updated testsuite for phpunit8 (@phil-davis, @JeroenVanOort) +* #495: refactored maps to use ::class notation (@JeroenVanOort) + +4.2.2 (2020-01-14) +------------------ + +* #465: Add TZ in iTip REPLY iTip messages +* #486: Add PHONE-NUMBER value type (used for TEL in vCard 3.0) + +4.2.1 (2019-12-18) +------------------ + +* #469, #451: fix compat with php 7.4 +* #443: prevent running in indefinite loop +* #449: Preventing creating a component for a root document +* #450: Fix parse with option Forgiving with trailing equal +* #459: fixed typo in VCalendar which resulting in usage of the wrong TimeZone +* #462: Broker::parseEventForOrganizer copies DTSTAMP from $eventInfo that causes broken scheduling + 4.2.0 (2019-02-19) ------------------ @@ -629,7 +744,7 @@ ChangeLog * Updated: Windows timezone mapping to latest version from unicode.org * Changed: The timezone maps are now loaded in from external files, in lib/Sabre/VObject/timezonedata. -* Added: Fixing badly encoded URL's from google contacts vcards. +* Added: Fixing badly encoded URL's from Google contacts vcards. * Fixed: Issue #68. Couldn't decode properties ending in a colon. * Fixed: Issue #72. RecurrenceIterator should respect timezone in the UNTIL clause. @@ -703,7 +818,7 @@ ChangeLog * Added: Utility to convert between 2.1, 3.0 and 4.0 vCards. * Added: You can now add() multiple parameters to a property in one call. * Added: Parameter::has() for easily checking if a parameter value exists. -* Added: VCard::preferred() to find a preferred email, phone number, etc for a +* Added: VCard::preferred() to find a preferred email, phone number, etc. for a contact. * Changed: All $duration properties are now public. * Added: A few validators for iCalendar documents. @@ -900,7 +1015,7 @@ ChangeLog ------------------ * Fixed: Microsoft re-uses their magic numbers for different timezones, - specifically id 2 for both Sarajevo and Lisbon). A workaround was added to + (specifically id 2 for both Sarajevo and Lisbon). A workaround was added to deal with this. diff --git a/bin/bench_freebusygenerator.php b/bin/bench_freebusygenerator.php index 963623d18..891335190 100644 --- a/bin/bench_freebusygenerator.php +++ b/bin/bench_freebusygenerator.php @@ -11,7 +11,7 @@ echo "The process will be repeated 100 times to get accurate stats\n"; echo "\n"; echo 'Usage: '.$argv[0]." inputfile.ics\n"; - exit(); + exit(1); } list(, $inputFile) = $argv; diff --git a/bin/bench_manipulatevcard.php b/bin/bench_manipulatevcard.php index df6d9f23d..96a506907 100644 --- a/bin/bench_manipulatevcard.php +++ b/bin/bench_manipulatevcard.php @@ -10,7 +10,7 @@ echo 'system.'; echo "\n"; echo 'Usage: '.$argv[0]." inputfile.vcf\n"; - exit(); + exit; } list(, $inputFile) = $argv; diff --git a/bin/generate_vcards b/bin/generate_vcards index 4663c3c16..758a4438f 100755 --- a/bin/generate_vcards +++ b/bin/generate_vcards @@ -3,8 +3,8 @@ namespace Sabre\VObject; -// This sucks.. we have to try to find the composer autoloader. But chances -// are, we can't find it this way. So we'll do our bestest +// This sucks. we have to try to find the composer autoloader. But chances +// are, we can't find it this way. So we'll do our best. $paths = [ __DIR__ . '/../vendor/autoload.php', // In case vobject is cloned directly __DIR__ . '/../../../autoload.php', // In case vobject is a composer dependency. diff --git a/bin/generateicalendardata.php b/bin/generateicalendardata.php index 019ed9745..a3dd3f24e 100755 --- a/bin/generateicalendardata.php +++ b/bin/generateicalendardata.php @@ -18,7 +18,7 @@ HI ); - exit(); + exit; } $events = 100; diff --git a/bin/mergeduplicates.php b/bin/mergeduplicates.php index 31b2c14ab..5e48c3c34 100755 --- a/bin/mergeduplicates.php +++ b/bin/mergeduplicates.php @@ -3,8 +3,8 @@ namespace Sabre\VObject; -// This sucks.. we have to try to find the composer autoloader. But chances -// are, we can't find it this way. So we'll do our bestest +// This sucks. We have to try to find the composer autoloader. But chances +// are, we can't find it this way. So we'll do our best. $paths = [ __DIR__.'/../vendor/autoload.php', // In case vobject is cloned directly __DIR__.'/../../../autoload.php', // In case vobject is a composer dependency. diff --git a/bin/rrulebench.php b/bin/rrulebench.php index 69008002e..c8be08d46 100644 --- a/bin/rrulebench.php +++ b/bin/rrulebench.php @@ -9,7 +9,7 @@ echo 'system.'; echo "\n"; echo 'Usage: '.$argv[0]." inputfile.ics startdate enddate\n"; - exit(); + exit; } list(, $inputFile, $startDate, $endDate) = $argv; diff --git a/bin/vobject b/bin/vobject index 2aca7e729..53d48ec73 100755 --- a/bin/vobject +++ b/bin/vobject @@ -3,8 +3,8 @@ namespace Sabre\VObject; -// This sucks.. we have to try to find the composer autoloader. But chances -// are, we can't find it this way. So we'll do our bestest +// This sucks. We have to try to find the composer autoloader. But chances +// are, we can't find it this way. So we'll do our best. $paths = [ __DIR__ . '/../vendor/autoload.php', // In case vobject is cloned directly __DIR__ . '/../../../autoload.php', // In case vobject is a composer dependency. diff --git a/composer.json b/composer.json index 5ab1e094d..263f6a166 100644 --- a/composer.json +++ b/composer.json @@ -32,15 +32,16 @@ "homepage" : "http://sabre.io/vobject/", "license" : "BSD-3-Clause", "require" : { - "php" : "^7.1 || ^8.0", + "php" : "^7.4 || ^8.0", "ext-mbstring" : "*", - "sabre/xml" : "^2.1" + "ext-json" : "*", + "sabre/xml" : "^3.0 || ^4.0" }, "require-dev" : { - "friendsofphp/php-cs-fixer": "~2.17.1", - "phpunit/phpunit" : "^7.5 || ^8.5 || ^9.0", + "friendsofphp/php-cs-fixer": "^3.38", + "phpunit/phpunit" : "^9.6", "phpunit/php-invoker" : "^2.0 || ^3.1", - "phpstan/phpstan": "^0.12" + "phpstan/phpstan": "^1.10" }, "suggest" : { "hoa/bench" : "If you would like to run the benchmark scripts" @@ -90,7 +91,7 @@ }, "scripts": { "phpstan": [ - "phpstan analyse lib tests" + "phpstan analyse lib tests --memory-limit 1G" ], "cs-fixer": [ "php-cs-fixer fix" diff --git a/lib/BirthdayCalendarGenerator.php b/lib/BirthdayCalendarGenerator.php index fade50e16..49793b0d4 100644 --- a/lib/BirthdayCalendarGenerator.php +++ b/lib/BirthdayCalendarGenerator.php @@ -15,31 +15,25 @@ class BirthdayCalendarGenerator { /** * Input objects. - * - * @var array */ - protected $objects = []; + protected array $objects = []; /** * Default year. * Used for dates without a year. */ - const DEFAULT_YEAR = 2000; + public const DEFAULT_YEAR = 2000; /** * Output format for the SUMMARY. - * - * @var string */ - protected $format = '%1$s\'s Birthday'; + protected string $format = '%1$s\'s Birthday'; /** * Creates the generator. * * Check the setTimeRange and setObjects methods for details about the * arguments. - * - * @param mixed $objects */ public function __construct($objects = null) { @@ -53,10 +47,8 @@ public function __construct($objects = null) * * You must either supply a vCard as a string or as a Component/VCard object. * It's also possible to supply an array of strings or objects. - * - * @param mixed $objects */ - public function setObjects($objects) + public function setObjects($objects): void { if (!is_array($objects)) { $objects = [$objects]; @@ -81,20 +73,16 @@ public function setObjects($objects) /** * Sets the output format for the SUMMARY. - * - * @param string $format */ - public function setFormat($format) + public function setFormat(string $format): void { $this->format = $format; } /** * Parses the input data and returns a VCALENDAR. - * - * @return Component/VCalendar */ - public function getResult() + public function getResult(): VCalendar { $calendar = new VCalendar(); @@ -111,7 +99,7 @@ public function getResult() continue; } - // We're always converting to vCard 4.0 so we can rely on the + // We're always converting to vCard 4.0, so we can rely on the // VCardConverter handling the X-APPLE-OMIT-YEAR property for us. $object = $object->convert(Document::VCARD40); diff --git a/lib/Cli.php b/lib/Cli.php index 816e2cb31..69af6f470 100644 --- a/lib/Cli.php +++ b/lib/Cli.php @@ -2,7 +2,9 @@ namespace Sabre\VObject; -use InvalidArgumentException; +use Sabre\VObject\Parser\Json; +use Sabre\VObject\Parser\MimeDir; +use Sabre\VObject\Parser\Parser; /** * This is the CLI interface for sabre-vobject. @@ -15,45 +17,28 @@ class Cli { /** * No output. - * - * @var bool - */ - protected $quiet = false; - - /** - * Help display. - * - * @var bool */ - protected $showHelp = false; + protected bool $quiet = false; /** * Whether to spit out 'mimedir' or 'json' format. - * - * @var string */ - protected $format; + protected ?string $format = null; /** * JSON pretty print. - * - * @var bool */ - protected $pretty; + protected bool $pretty = false; /** * Source file. - * - * @var string */ - protected $inputPath; + protected string $inputPath; /** * Destination file. - * - * @var string */ - protected $outputPath; + protected string $outputPath; /** * output stream. @@ -78,24 +63,18 @@ class Cli /** * Input format (one of json or mimedir). - * - * @var string */ - protected $inputFormat; + protected ?string $inputFormat = null; /** * Makes the parser less strict. - * - * @var bool */ - protected $forgiving = false; + protected bool $forgiving = false; /** * Main function. - * - * @return int */ - public function main(array $argv) + public function main(array $argv): int { // @codeCoverageIgnoreStart // We cannot easily test this, so we'll skip it. Pretty basic anyway. @@ -130,34 +109,31 @@ public function main(array $argv) $this->showHelp(); return 0; - break; case 'format': switch ($value) { // jcard/jcal documents case 'jcard': case 'jcal': - // specific document versions + // specific document versions case 'vcard21': case 'vcard30': case 'vcard40': case 'icalendar20': - // specific formats + // specific formats case 'json': case 'mimedir': - // icalendar/vcad + // icalendar/vcard case 'icalendar': case 'vcard': $this->format = $value; break; default: - throw new InvalidArgumentException('Unknown format: '.$value); + throw new \InvalidArgumentException('Unknown format: '.$value); } break; case 'pretty': - if (version_compare(PHP_VERSION, '5.4.0') >= 0) { - $this->pretty = true; - } + $this->pretty = true; break; case 'forgiving': $this->forgiving = true; @@ -171,7 +147,7 @@ public function main(array $argv) $this->inputFormat = 'json'; break; - // mimedir formats + // mimedir formats case 'mimedir': case 'icalendar': case 'vcard': @@ -183,11 +159,11 @@ public function main(array $argv) break; default: - throw new InvalidArgumentException('Unknown format: '.$value); + throw new \InvalidArgumentException('Unknown format: '.$value); } break; default: - throw new InvalidArgumentException('Unknown option: '.$name); + throw new \InvalidArgumentException('Unknown option: '.$name); } } @@ -198,17 +174,17 @@ public function main(array $argv) } if (1 === count($positional)) { - throw new InvalidArgumentException('Inputfile is a required argument'); + throw new \InvalidArgumentException('Inputfile is a required argument'); } if (count($positional) > 3) { - throw new InvalidArgumentException('Too many arguments'); + throw new \InvalidArgumentException('Too many arguments'); } if (!in_array($positional[0], ['validate', 'repair', 'convert', 'color'])) { - throw new InvalidArgumentException('Unknown command: '.$positional[0]); + throw new \InvalidArgumentException('Unknown command: '.$positional[0]); } - } catch (InvalidArgumentException $e) { + } catch (\InvalidArgumentException $e) { $this->showHelp(); $this->log('Error: '.$e->getMessage(), 'red'); @@ -218,20 +194,20 @@ public function main(array $argv) $command = $positional[0]; $this->inputPath = $positional[1]; - $this->outputPath = isset($positional[2]) ? $positional[2] : '-'; + $this->outputPath = $positional[2] ?? '-'; if ('-' !== $this->outputPath) { $this->stdout = fopen($this->outputPath, 'w'); } - if (!$this->inputFormat) { + if (null === $this->inputFormat) { if ('.json' === substr($this->inputPath, -5)) { $this->inputFormat = 'json'; } else { $this->inputFormat = 'mimedir'; } } - if (!$this->format) { + if (null === $this->format) { if ('.json' === substr($this->outputPath, -5)) { $this->format = 'json'; } else { @@ -262,7 +238,7 @@ public function main(array $argv) /** * Shows the help message. */ - protected function showHelp() + protected function showHelp(): void { $this->log('Usage:', 'yellow'); $this->log(' vobject [options] command [arguments]'); @@ -275,10 +251,7 @@ protected function showHelp() $this->log(' vcard30, vcard40, icalendar20, jcal, jcard, json, mimedir.'); $this->log($this->colorize('green', ' --inputformat ').'If the input format cannot be guessed from the extension, it'); $this->log(' must be specified here.'); - // Only PHP 5.4 and up - if (version_compare(PHP_VERSION, '5.4.0') >= 0) { - $this->log($this->colorize('green', ' --pretty ').'json pretty-print.'); - } + $this->log($this->colorize('green', ' --pretty ').'json pretty-print.'); $this->log(''); $this->log('Commands:', 'yellow'); $this->log($this->colorize('green', ' validate').' source_file Validates a file for correctness.'); @@ -286,7 +259,7 @@ protected function showHelp() $this->log($this->colorize('green', ' convert').' source_file [output_file] Converts a file.'); $this->log($this->colorize('green', ' color').' source_file Colorize a file, useful for debugging.'); $this->log( - <<stdout, $this->serializeComponent($vObj)); + $this->serializeComponent($vObj); + + return 0; } /** * Returns an ansi color string for a color name. - * - * @param string $color - * - * @return string */ - protected function colorize($color, $str, $resetTo = 'default') + protected function colorize(string $color, string $str, string $resetTo = 'default'): string { $colors = [ 'cyan' => '1;36', @@ -483,16 +444,13 @@ protected function colorize($color, $str, $resetTo = 'default') /** * Writes out a string in specific color. - * - * @param string $color - * @param string $str */ - protected function cWrite($color, $str) + protected function cWrite(string $color, string $str): void { fwrite($this->stdout, $this->colorize($color, $str)); } - protected function serializeComponent(Component $vObj) + protected function serializeComponent(Component $vObj): void { $this->cWrite('cyan', 'BEGIN'); $this->cWrite('red', ':'); @@ -507,48 +465,40 @@ protected function serializeComponent(Component $vObj) * To avoid score collisions, each "score category" has a reasonable * space to accommodate elements. The $key is added to the $score to * preserve the original relative order of elements. - * - * @param int $key - * @param array $array - * - * @return int */ - $sortScore = function ($key, $array) { + $sortScore = function (int $key, array $array): int { if ($array[$key] instanceof Component) { // We want to encode VTIMEZONE first, this is a personal // preference. if ('VTIMEZONE' === $array[$key]->name) { $score = 300000000; - - return $score + $key; } else { $score = 400000000; - - return $score + $key; } - } else { - // Properties get encoded first - // VCARD version 4.0 wants the VERSION property to appear first - if ($array[$key] instanceof Property) { - if ('VERSION' === $array[$key]->name) { - $score = 100000000; - - return $score + $key; - } else { - // All other properties - $score = 200000000; - return $score + $key; - } + return $score + $key; + } + // Properties get encoded first + // VCARD version 4.0 wants the VERSION property to appear first + if ($array[$key] instanceof Property) { + if ('VERSION' === $array[$key]->name) { + $score = 100000000; + } else { + // All other properties + $score = 200000000; } + + return $score + $key; } + + return 0; }; $children = $vObj->children(); $tmp = $children; uksort( $children, - function ($a, $b) use ($sortScore, $tmp) { + function ($a, $b) use ($sortScore, $tmp): int { $sA = $sortScore($a, $tmp); $sB = $sortScore($b, $tmp); @@ -572,7 +522,7 @@ function ($a, $b) use ($sortScore, $tmp) { /** * Colorizes a property. */ - protected function serializeProperty(Property $property) + protected function serializeProperty(Property $property): void { if ($property->group) { $this->cWrite('default', $property->group); @@ -630,7 +580,7 @@ protected function serializeProperty(Property $property) /** * Parses the list of arguments. */ - protected function parseArguments(array $argv) + protected function parseArguments(array $argv): array { $positional = []; $options = []; @@ -664,14 +614,16 @@ protected function parseArguments(array $argv) return [$options, $positional]; } - protected $parser; + protected ?Parser $parser = null; /** * Reads the input file. * - * @return Component + * @throws EofException + * @throws ParseException + * @throws InvalidDataException */ - protected function readInput() + protected function readInput(): ?Document { if (!$this->parser) { if ('-' !== $this->inputPath) { @@ -679,9 +631,9 @@ protected function readInput() } if ('mimedir' === $this->inputFormat) { - $this->parser = new Parser\MimeDir($this->stdin, ($this->forgiving ? Reader::OPTION_FORGIVING : 0)); + $this->parser = new MimeDir($this->stdin, $this->forgiving ? Reader::OPTION_FORGIVING : 0); } else { - $this->parser = new Parser\Json($this->stdin, ($this->forgiving ? Reader::OPTION_FORGIVING : 0)); + $this->parser = new Json($this->stdin, $this->forgiving ? Reader::OPTION_FORGIVING : 0); } } @@ -690,10 +642,8 @@ protected function readInput() /** * Sends a message to STDERR. - * - * @param string $msg */ - protected function log($msg, $color = 'default') + protected function log(string $msg, string $color = 'default'): void { if (!$this->quiet) { if ('default' !== $color) { diff --git a/lib/Component.php b/lib/Component.php index c1a63258e..426695470 100644 --- a/lib/Component.php +++ b/lib/Component.php @@ -2,6 +2,7 @@ namespace Sabre\VObject; +use Sabre\VObject; use Sabre\Xml; /** @@ -13,6 +14,8 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\FlatText UID */ class Component extends Node { @@ -20,17 +23,15 @@ class Component extends Node * Component name. * * This will contain a string such as VEVENT, VTODO, VCALENDAR, VCARD. - * - * @var string */ - public $name; + public string $name; /** * A list of properties and/or sub-components. * - * @var array + * @var array */ - protected $children = []; + protected array $children = []; /** * Creates a new component. @@ -43,12 +44,11 @@ class Component extends Node * an iCalendar object, this may be something like CALSCALE:GREGORIAN. To * ensure that this does not happen, set $defaults to false. * - * @param string $name such as VCALENDAR, VEVENT - * @param bool $defaults + * @param string|null $name such as VCALENDAR, VEVENT */ - public function __construct(Document $root, $name, array $children = [], $defaults = true) + public function __construct(Document $root, ?string $name, array $children = [], bool $defaults = true) { - $this->name = strtoupper($name); + $this->name = isset($name) ? strtoupper($name) : ''; $this->root = $root; if ($defaults) { @@ -97,10 +97,8 @@ public function __construct(Document $root, $name, array $children = [], $defaul * add($name, $value, array $parameters = []) // Adds a new property * add($name, array $children = []) // Adds a new component * by name. - * - * @return Node */ - public function add() + public function add(): Node { $arguments = func_get_args(); @@ -116,6 +114,7 @@ public function add() throw new \InvalidArgumentException('The first argument must either be a \\Sabre\\VObject\\Node or a string'); } + /** @var Component|Property|Parameter $newNode */ $name = $newNode->name; if (isset($this->children[$name])) { $this->children[$name][] = $newNode; @@ -136,10 +135,10 @@ public function add() * * @param string|Property|Component $item */ - public function remove($item) + public function remove($item): void { if (is_string($item)) { - // If there's no dot in the name, it's an exact property name and + // If there's no dot in the name, it's an exact property name, // we can just wipe out all those properties. // if (false === strpos($item, '.')) { @@ -168,10 +167,8 @@ public function remove($item) /** * Returns a flat list of all the properties and components in this * component. - * - * @return array */ - public function children() + public function children(): array { $result = []; foreach ($this->children as $childGroup) { @@ -184,10 +181,8 @@ public function children() /** * This method only returns a list of sub-components. Properties are * ignored. - * - * @return array */ - public function getComponents() + public function getComponents(): array { $result = []; @@ -211,15 +206,11 @@ public function getComponents() * search for a property in a specific group, you can select on the entire * string ("HOME.EMAIL"). If you want to search on a specific property that * has not been assigned a group, specify ".EMAIL". - * - * @param string|null $name - * - * @return array */ - public function select($name) + public function select(string $name): array { $group = null; - $name = is_null($name) ? '' : strtoupper($name); + $name = strtoupper($name); if (false !== strpos($name, '.')) { list($group, $name) = explode('.', $name, 2); } @@ -228,7 +219,7 @@ public function select($name) } if (!is_null($name)) { - $result = isset($this->children[$name]) ? $this->children[$name] : []; + $result = $this->children[$name] ?? []; if (is_null($group)) { return $result; @@ -238,7 +229,7 @@ public function select($name) return array_filter( $result, function ($child) use ($group) { - return $child instanceof Property && strtoupper($child->group ?? '') === $group; + return $child instanceof Property && (null !== $child->group ? strtoupper($child->group) : '') === $group; } ); } @@ -249,7 +240,7 @@ function ($child) use ($group) { $result = []; foreach ($this->children as $childGroup) { foreach ($childGroup as $child) { - if ($child instanceof Property && $child->group && strtoupper($child->group) === $group) { + if ($child instanceof Property && (null !== $child->group ? strtoupper($child->group) : '') === $group) { $result[] = $child; } } @@ -260,10 +251,8 @@ function ($child) use ($group) { /** * Turns the object back into a serialized blob. - * - * @return string */ - public function serialize() + public function serialize(): string { $str = 'BEGIN:'.$this->name."\r\n"; @@ -282,42 +271,39 @@ public function serialize() * * @return int */ - $sortScore = function ($key, $array) { + $sortScore = function (int $key, array $array): ?int { if ($array[$key] instanceof Component) { // We want to encode VTIMEZONE first, this is a personal // preference. if ('VTIMEZONE' === $array[$key]->name) { $score = 300000000; - - return $score + $key; } else { $score = 400000000; - - return $score + $key; } - } else { - // Properties get encoded first - // VCARD version 4.0 wants the VERSION property to appear first - if ($array[$key] instanceof Property) { - if ('VERSION' === $array[$key]->name) { - $score = 100000000; - - return $score + $key; - } else { - // All other properties - $score = 200000000; - - return $score + $key; - } + + return $score + $key; + } + // Properties get encoded first + // VCARD version 4.0 wants the VERSION property to appear first + if ($array[$key] instanceof Property) { + if ('VERSION' === $array[$key]->name) { + $score = 100000000; + } else { + // All other properties + $score = 200000000; } + + return $score + $key; } + + return 0; }; $children = $this->children(); $tmp = $children; uksort( $children, - function ($a, $b) use ($sortScore, $tmp) { + function ($a, $b) use ($sortScore, $tmp): int { $sA = $sortScore($a, $tmp); $sB = $sortScore($b, $tmp); @@ -336,11 +322,9 @@ function ($a, $b) use ($sortScore, $tmp) { /** * This method returns an array, with the representation as it should be * encoded in JSON. This is used to create jCard or jCal documents. - * - * @return array */ #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): array { $components = []; $properties = []; @@ -368,7 +352,7 @@ public function jsonSerialize() * * @param Xml\Writer $writer XML writer */ - public function xmlSerialize(Xml\Writer $writer) + public function xmlSerialize(Xml\Writer $writer): void { $components = []; $properties = []; @@ -410,10 +394,8 @@ public function xmlSerialize(Xml\Writer $writer) /** * This method should return a list of default property values. - * - * @return array */ - protected function getDefaults() + protected function getDefaults(): array { return []; } @@ -430,11 +412,9 @@ protected function getDefaults() * * $event = $calendar->VEVENT; * - * @param string $name - * - * @return Property|null + * @return Property|Component|null */ - public function __get($name) + public function __get(string $name): ?Node { if ('children' === $name) { throw new \RuntimeException('Starting sabre/vobject 4.0 the children property is now protected. You should use the children() method instead'); @@ -442,7 +422,7 @@ public function __get($name) $matches = $this->select($name); if (0 === count($matches)) { - return; + return null; } else { $firstMatch = current($matches); /* @var $firstMatch Property */ @@ -454,12 +434,8 @@ public function __get($name) /** * This method checks if a sub-element with the specified name exists. - * - * @param string $name - * - * @return bool */ - public function __isset($name) + public function __isset(string $name): bool { $matches = $this->select($name); @@ -474,11 +450,8 @@ public function __isset($name) * * If the item already exists, it will be removed. If you want to add * a new item with the same name, always use the add() method. - * - * @param string $name - * @param mixed $value */ - public function __set($name, $value) + public function __set(string $name, $value): void { $name = strtoupper($name); $this->remove($name); @@ -492,10 +465,8 @@ public function __set($name, $value) /** * Removes all properties and components within this component with the * specified name. - * - * @param string $name */ - public function __unset($name) + public function __unset(string $name): void { $this->remove($name); } @@ -536,10 +507,8 @@ public function __clone() * * See the VEVENT implementation for getValidationRules for a more complex * example. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return []; } @@ -563,12 +532,8 @@ public function getValidationRules() * 1 - The issue was repaired (only happens if REPAIR was turned on). * 2 - A warning. * 3 - An error. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $rules = $this->getValidationRules(); $defaults = $this->getDefaults(); @@ -659,7 +624,7 @@ public function validate($options = 0) * It's intended to remove all circular references, so PHP can easily clean * it up. */ - public function destroy() + public function destroy(): void { parent::destroy(); foreach ($this->children as $childGroup) { diff --git a/lib/Component/Available.php b/lib/Component/Available.php index 5510b9e0a..b3ba40b07 100644 --- a/lib/Component/Available.php +++ b/lib/Component/Available.php @@ -13,6 +13,10 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Ivan Enderlin * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\DateTime DTSTART + * @property VObject\Property\ICalendar\DateTime DTEND + * @property VObject\Property\ICalendar\Duration DURATION */ class Available extends VObject\Component { @@ -26,9 +30,9 @@ class Available extends VObject\Component * If either the start or end is 'unbounded' its value will be null * instead. * - * @return array + * @throws VObject\InvalidDataException */ - public function getEffectiveStartEnd() + public function getEffectiveStartEnd(): array { $effectiveStart = $this->DTSTART->getDateTime(); if (isset($this->DTEND)) { @@ -52,10 +56,8 @@ public function getEffectiveStartEnd() * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'UID' => 1, @@ -101,12 +103,8 @@ public function getValidationRules() * 1 - The issue was repaired (only happens if REPAIR was turned on). * 2 - A warning. * 3 - An error. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $result = parent::validate($options); diff --git a/lib/Component/VAlarm.php b/lib/Component/VAlarm.php index bd00eb600..3e5797b0a 100644 --- a/lib/Component/VAlarm.php +++ b/lib/Component/VAlarm.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeImmutable; -use DateTimeInterface; use Sabre\VObject; use Sabre\VObject\InvalidDataException; @@ -15,6 +13,12 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\DateTime DTSTART + * @property VObject\Property\ICalendar\DateTime DTEND + * @property VObject\Property\ICalendar\Duration DURATION + * @property VObject\Property\ICalendar\Duration|VObject\Property\ICalendar\DateTime TRIGGER + * @property VObject\Property\IntegerValue REPEAT */ class VAlarm extends VObject\Component { @@ -23,15 +27,16 @@ class VAlarm extends VObject\Component * * This ignores repeated alarm, only the first trigger is returned. * - * @return DateTimeImmutable + * @throws InvalidDataException */ - public function getEffectiveTriggerTime() + public function getEffectiveTriggerTime(): \DateTimeImmutable { $trigger = $this->TRIGGER; - if (!isset($trigger['VALUE']) || 'DURATION' === strtoupper($trigger['VALUE'])) { + if (!isset($trigger['VALUE']) || ($trigger['VALUE'] && 'DURATION' === strtoupper($trigger['VALUE']))) { $triggerDuration = VObject\DateTimeParser::parseDuration($this->TRIGGER); $related = (isset($trigger['RELATED']) && 'END' == strtoupper($trigger['RELATED'])) ? 'END' : 'START'; + /** @var VEvent|VTodo $parentComponent */ $parentComponent = $this->parent; if ('START' === $related) { if ('VTODO' === $parentComponent->name) { @@ -41,7 +46,6 @@ public function getEffectiveTriggerTime() } $effectiveTrigger = $parentComponent->$propName->getDateTime(); - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); } else { if ('VTODO' === $parentComponent->name) { $endProp = 'DUE'; @@ -53,17 +57,15 @@ public function getEffectiveTriggerTime() if (isset($parentComponent->$endProp)) { $effectiveTrigger = $parentComponent->$endProp->getDateTime(); - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); } elseif (isset($parentComponent->DURATION)) { $effectiveTrigger = $parentComponent->DTSTART->getDateTime(); $duration = VObject\DateTimeParser::parseDuration($parentComponent->DURATION); $effectiveTrigger = $effectiveTrigger->add($duration); - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); } else { $effectiveTrigger = $parentComponent->DTSTART->getDateTime(); - $effectiveTrigger = $effectiveTrigger->add($triggerDuration); } } + $effectiveTrigger = $effectiveTrigger->add($triggerDuration); } else { $effectiveTrigger = $trigger->getDateTime(); } @@ -78,12 +80,9 @@ public function getEffectiveTriggerTime() * The rules used to determine if an event falls within the specified * time-range is based on the CalDAV specification. * - * @param DateTime $start - * @param DateTime $end - * - * @return bool + * @throws InvalidDataException */ - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) + public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end): bool { $effectiveTrigger = $this->getEffectiveTriggerTime(); @@ -120,10 +119,8 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'ACTION' => 1, diff --git a/lib/Component/VAvailability.php b/lib/Component/VAvailability.php index 04ec38dcb..ff6e9bd65 100644 --- a/lib/Component/VAvailability.php +++ b/lib/Component/VAvailability.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeInterface; use Sabre\VObject; /** @@ -14,6 +13,10 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Ivan Enderlin * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\DateTime DTSTART + * @property VObject\Property\ICalendar\DateTime DTEND + * @property VObject\Property\ICalendar\Duration DURATION */ class VAvailability extends VObject\Component { @@ -26,15 +29,15 @@ class VAvailability extends VObject\Component * * https://tools.ietf.org/html/draft-daboo-calendar-availability-05#section-3.1 * - * @return bool + * @throws VObject\InvalidDataException */ - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) + public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end): bool { list($effectiveStart, $effectiveEnd) = $this->getEffectiveStartEnd(); return - (is_null($effectiveStart) || $start < $effectiveEnd) && - (is_null($effectiveEnd) || $end > $effectiveStart) + (is_null($effectiveStart) || $start < $effectiveEnd) + && (is_null($effectiveEnd) || $end > $effectiveStart) ; } @@ -48,9 +51,9 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) * If either the start or end is 'unbounded' its value will be null * instead. * - * @return array + * @throws VObject\InvalidDataException */ - public function getEffectiveStartEnd() + public function getEffectiveStartEnd(): array { $effectiveStart = null; $effectiveEnd = null; @@ -79,10 +82,8 @@ public function getEffectiveStartEnd() * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'UID' => 1, @@ -127,12 +128,8 @@ public function getValidationRules() * 1 - The issue was repaired (only happens if REPAIR was turned on). * 2 - A warning. * 3 - An error. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $result = parent::validate($options); diff --git a/lib/Component/VCalendar.php b/lib/Component/VCalendar.php index 4db318135..b317e02c8 100644 --- a/lib/Component/VCalendar.php +++ b/lib/Component/VCalendar.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeInterface; -use DateTimeZone; use Sabre\VObject; use Sabre\VObject\Component; use Sabre\VObject\InvalidDataException; @@ -19,6 +17,11 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VEvent VEVENT + * @property VJournal VJOURNAL + * @property VObject\Property\Text ORG + * @property VObject\Property\FlatText METHOD */ class VCalendar extends VObject\Document { @@ -26,17 +29,13 @@ class VCalendar extends VObject\Document * The default name for this component. * * This should be 'VCALENDAR' or 'VCARD'. - * - * @var string */ - public static $defaultName = 'VCALENDAR'; + public static ?string $defaultName = 'VCALENDAR'; /** * This is a list of components, and which classes they should map to. - * - * @var array */ - public static $componentMap = [ + public static array $componentMap = [ 'VCALENDAR' => self::class, 'VALARM' => VAlarm::class, 'VEVENT' => VEvent::class, @@ -50,10 +49,8 @@ class VCalendar extends VObject\Document /** * List of value-types, and which classes they map to. - * - * @var array */ - public static $valueMap = [ + public static array $valueMap = [ 'BINARY' => VObject\Property\Binary::class, 'BOOLEAN' => VObject\Property\Boolean::class, 'CAL-ADDRESS' => VObject\Property\ICalendar\CalAddress::class, @@ -73,10 +70,8 @@ class VCalendar extends VObject\Document /** * List of properties, and which classes they map to. - * - * @var array */ - public static $propertyMap = [ + public static array $propertyMap = [ // Calendar properties 'CALSCALE' => VObject\Property\FlatText::class, 'METHOD' => VObject\Property\FlatText::class, @@ -154,10 +149,8 @@ class VCalendar extends VObject\Document /** * Returns the current document type. - * - * @return int */ - public function getDocumentType() + public function getDocumentType(): int { return self::ICALENDAR20; } @@ -169,13 +162,13 @@ public function getDocumentType() * * VTIMEZONE components will always be excluded. * - * @param string $componentName filter by component name + * @param string|null $componentName filter by component name * * @return VObject\Component[] */ - public function getBaseComponents($componentName = null) + public function getBaseComponents(string $componentName = null): array { - $isBaseComponent = function ($component) { + $isBaseComponent = function ($component): bool { if (!$component instanceof VObject\Component) { return false; } @@ -220,13 +213,13 @@ public function getBaseComponents($componentName = null) * * If there is no such component, null will be returned. * - * @param string $componentName filter by component name + * @param string|null $componentName filter by component name * * @return VObject\Component|null */ - public function getBaseComponent($componentName = null) + public function getBaseComponent(string $componentName = null): ?Component { - $isBaseComponent = function ($component) { + $isBaseComponent = function ($component): bool { if (!$component instanceof VObject\Component) { return false; } @@ -270,34 +263,35 @@ public function getBaseComponent($componentName = null) * can be used to expand the event into multiple sub-events. * * Each event will be stripped from its recurrence information, and only - * the instances of the event in the specified timerange will be left + * the instances of the event in the specified time range will be left * alone. * * In addition, this method will cause timezone information to be stripped, * and normalized to UTC. * - * @param DateTimeZone $timeZone reference timezone for floating dates and - * times + * @param \DateTimeZone|null $timeZone reference timezone for floating dates and + * times * - * @return VCalendar + * @throws InvalidDataException + * @throws VObject\Recur\MaxInstancesExceededException */ - public function expand(DateTimeInterface $start, DateTimeInterface $end, DateTimeZone $timeZone = null) + public function expand(\DateTimeInterface $start, \DateTimeInterface $end, \DateTimeZone $timeZone = null): VCalendar { $newChildren = []; $recurringEvents = []; if (!$timeZone) { - $timeZone = new DateTimeZone('UTC'); + $timeZone = new \DateTimeZone('UTC'); } - $stripTimezones = function (Component $component) use ($timeZone, &$stripTimezones) { + $stripTimezones = function (Component $component) use ($timeZone, &$stripTimezones): Component { foreach ($component->children() as $componentChild) { if ($componentChild instanceof Property\ICalendar\DateTime && $componentChild->hasTime()) { $dt = $componentChild->getDateTimes($timeZone); // We only need to update the first timezone, because // setDateTimes will match all other timezones to the // first. - $dt[0] = $dt[0]->setTimeZone(new DateTimeZone('UTC')); + $dt[0] = $dt[0]->setTimeZone(new \DateTimeZone('UTC')); $componentChild->setDateTimes($dt); } elseif ($componentChild instanceof Component) { $stripTimezones($componentChild); @@ -356,10 +350,8 @@ public function expand(DateTimeInterface $start, DateTimeInterface $end, DateTim /** * This method should return a list of default property values. - * - * @return array */ - protected function getDefaults() + protected function getDefaults(): array { return [ 'VERSION' => '2.0', @@ -380,10 +372,8 @@ protected function getDefaults() * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'PRODID' => 1, @@ -413,12 +403,8 @@ public function getValidationRules() * 1 - The issue was repaired (only happens if REPAIR was turned on). * 2 - A warning. * 3 - An error. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $warnings = parent::validate($options); @@ -511,10 +497,8 @@ public function validate($options = 0) /** * Returns all components with a specific UID value. - * - * @return array */ - public function getByUID($uid) + public function getByUID($uid): array { return array_filter($this->getComponents(), function ($item) use ($uid) { if (!$itemUid = $item->select('UID')) { diff --git a/lib/Component/VCard.php b/lib/Component/VCard.php index eac789842..0f2a5e266 100644 --- a/lib/Component/VCard.php +++ b/lib/Component/VCard.php @@ -14,6 +14,10 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\FlatText FN + * @property VObject\Property\Text ORG + * @property VObject\Property\FlatText EMAIL */ class VCard extends VObject\Document { @@ -21,33 +25,25 @@ class VCard extends VObject\Document * The default name for this component. * * This should be 'VCALENDAR' or 'VCARD'. - * - * @var string */ - public static $defaultName = 'VCARD'; + public static ?string $defaultName = 'VCARD'; /** * Caching the version number. - * - * @var int */ - private $version = null; + private ?int $version = null; /** * This is a list of components, and which classes they should map to. - * - * @var array */ - public static $componentMap = [ + public static array $componentMap = [ 'VCARD' => VCard::class, ]; /** * List of value-types, and which classes they map to. - * - * @var array */ - public static $valueMap = [ + public static array $valueMap = [ 'BINARY' => VObject\Property\Binary::class, 'BOOLEAN' => VObject\Property\Boolean::class, 'CONTENT-ID' => VObject\Property\FlatText::class, // vCard 2.1 only @@ -69,10 +65,8 @@ class VCard extends VObject\Document /** * List of properties, and which classes they map to. - * - * @var array */ - public static $propertyMap = [ + public static array $propertyMap = [ // vCard 2.1 properties and up 'N' => VObject\Property\Text::class, 'FN' => VObject\Property\FlatText::class, @@ -140,10 +134,8 @@ class VCard extends VObject\Document /** * Returns the current document type. - * - * @return int */ - public function getDocumentType() + public function getDocumentType(): int { if (!$this->version) { $version = (string) $this->VERSION; @@ -178,11 +170,9 @@ public function getDocumentType() * * If input and output version are identical, a clone is returned. * - * @param int $target - * - * @return VCard + * @throws VObject\InvalidDataException */ - public function convert($target) + public function convert(int $target): VCard { $converter = new VObject\VCardConverter(); @@ -194,7 +184,7 @@ public function convert($target) * * If the VCARD doesn't know its version, 2.1 is assumed. */ - const DEFAULT_VERSION = self::VCARD21; + public const DEFAULT_VERSION = self::VCARD21; /** * Validates the node for correctness. @@ -213,12 +203,8 @@ public function convert($target) * 1 - The issue was repaired (only happens if REPAIR was turned on) * 2 - An inconsequential issue * 3 - A severe issue. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $warnings = []; @@ -291,6 +277,11 @@ public function validate($options = 0) $this->FN = (string) $this->ORG; $repaired = true; + // Otherwise, the NICKNAME property may work + } elseif (isset($this->NICKNAME)) { + $this->FN = (string) $this->NICKNAME; + $repaired = true; + // Otherwise, the EMAIL property may work } elseif (isset($this->EMAIL)) { $this->FN = (string) $this->EMAIL; @@ -322,10 +313,8 @@ public function validate($options = 0) * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'ADR' => '*', @@ -379,12 +368,8 @@ public function getValidationRules() * * If neither of those parameters are specified, the first is returned, if * a field with that name does not exist, null is returned. - * - * @param string $fieldName - * - * @return VObject\Property|null */ - public function preferred($propertyName) + public function preferred(string $propertyName): ?VObject\Property { $preferred = null; $lastPref = 101; @@ -411,26 +396,23 @@ public function preferred($propertyName) * This function will return null if the property does not exist. If there are * multiple properties with the same TYPE value, only one will be returned. * - * @param string $propertyName - * @param string $type - * - * @return VObject\Property|null + * @return \ArrayAccess|array|null */ - public function getByType($propertyName, $type) + public function getByType(string $propertyName, string $type) { foreach ($this->select($propertyName) as $field) { if (isset($field['TYPE']) && $field['TYPE']->has($type)) { return $field; } } + + return null; } /** * This method should return a list of default property values. - * - * @return array */ - protected function getDefaults() + protected function getDefaults(): array { return [ 'VERSION' => '4.0', @@ -442,11 +424,9 @@ protected function getDefaults() /** * This method returns an array, with the representation as it should be * encoded in json. This is used to create jCard or jCal documents. - * - * @return array */ #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): array { // A vcard does not have sub-components, so we're overriding this // method to remove that array element. @@ -465,10 +445,8 @@ public function jsonSerialize() /** * This method serializes the data into XML. This is used to create xCard or * xCal documents. - * - * @param Xml\Writer $writer XML writer */ - public function xmlSerialize(Xml\Writer $writer) + public function xmlSerialize(Xml\Writer $writer): void { $propertiesByGroup = []; @@ -517,12 +495,8 @@ public function xmlSerialize(Xml\Writer $writer) /** * Returns the default class for a property name. - * - * @param string $propertyName - * - * @return string */ - public function getClassNameForPropertyName($propertyName) + public function getClassNameForPropertyName(string $propertyName): string { $className = parent::getClassNameForPropertyName($propertyName); diff --git a/lib/Component/VEvent.php b/lib/Component/VEvent.php index 6ea93ed5e..e29e56322 100644 --- a/lib/Component/VEvent.php +++ b/lib/Component/VEvent.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeInterface; use Sabre\VObject; use Sabre\VObject\Recur\EventIterator; use Sabre\VObject\Recur\NoInstancesException; @@ -15,6 +14,18 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\DateTime DTSTART + * @property VObject\Property\ICalendar\DateTime DTEND + * @property VObject\Property\ICalendar\DateTime DTSTAMP + * @property VObject\Property\ICalendar\Duration DURATION + * @property VObject\Property\ICalendar\Recur RRULE + * @property VObject\Property\ICalendar\DateTime[] EXDATE + * @property VObject\Property\ICalendar\DateTime RDATE + * @property VObject\Property\ICalendar\Recur EXRULE + * @property VObject\Property\ICalendar\DateTime RECURRENCE-ID + * @property VObject\Property\FlatText TRANSP + * @property VObject\Property\FlatText STATUS */ class VEvent extends VObject\Component { @@ -25,9 +36,10 @@ class VEvent extends VObject\Component * The rules used to determine if an event falls within the specified * time-range is based on the CalDAV specification. * - * @return bool + * @throws VObject\InvalidDataException + * @throws VObject\Recur\MaxInstancesExceededException */ - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) + public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end): bool { if ($this->RRULE) { try { @@ -44,14 +56,14 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) // recurrence instance exceeded the start of the requested // time-range. // - // If the starttime of the recurrence did not exceed the + // If the start time of the recurrence did not exceed the // end of the time range as well, we have a match. return $it->getDTStart() < $end && $it->getDTEnd() > $start; } $effectiveStart = $this->DTSTART->getDateTime($start->getTimezone()); if (isset($this->DTEND)) { - // The DTEND property is considered non inclusive. So for a 3 day + // The DTEND property is considered non-inclusive. So for a 3-day // event in july, dtstart and dtend would have to be July 1st and // July 4th respectively. // @@ -73,10 +85,8 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) /** * This method should return a list of default property values. - * - * @return array */ - protected function getDefaults() + protected function getDefaults(): array { return [ 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), @@ -96,10 +106,8 @@ protected function getDefaults() * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { $hasMethod = isset($this->parent->METHOD); diff --git a/lib/Component/VFreeBusy.php b/lib/Component/VFreeBusy.php index fef418b53..a9891c92c 100644 --- a/lib/Component/VFreeBusy.php +++ b/lib/Component/VFreeBusy.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeInterface; use Sabre\VObject; /** @@ -14,6 +13,8 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\Period FREEBUSY */ class VFreeBusy extends VObject\Component { @@ -21,9 +22,9 @@ class VFreeBusy extends VObject\Component * Checks based on the contained FREEBUSY information, if a timeslot is * available. * - * @return bool + * @throws VObject\InvalidDataException */ - public function isFree(DateTimeInterface $start, DatetimeInterface $end) + public function isFree(\DateTimeInterface $start, \DatetimeInterface $end): bool { foreach ($this->select('FREEBUSY') as $freebusy) { // We are only interested in FBTYPE=BUSY (the default), @@ -69,10 +70,8 @@ public function isFree(DateTimeInterface $start, DatetimeInterface $end) * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'UID' => 1, diff --git a/lib/Component/VJournal.php b/lib/Component/VJournal.php index 9b7f1b873..30e40adf7 100644 --- a/lib/Component/VJournal.php +++ b/lib/Component/VJournal.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeInterface; use Sabre\VObject; /** @@ -13,6 +12,8 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\DateTime DTSTART */ class VJournal extends VObject\Component { @@ -23,9 +24,9 @@ class VJournal extends VObject\Component * The rules used to determine if an event falls within the specified * time-range is based on the CalDAV specification. * - * @return bool + * @throws VObject\InvalidDataException */ - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) + public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end): bool { $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; if ($dtstart) { @@ -52,10 +53,8 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'UID' => 1, @@ -88,10 +87,8 @@ public function getValidationRules() /** * This method should return a list of default property values. - * - * @return array */ - protected function getDefaults() + protected function getDefaults(): array { return [ 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), diff --git a/lib/Component/VTimeZone.php b/lib/Component/VTimeZone.php index 21c062377..9dcf9b976 100644 --- a/lib/Component/VTimeZone.php +++ b/lib/Component/VTimeZone.php @@ -2,6 +2,7 @@ namespace Sabre\VObject\Component; +use DateTimeZone; use Sabre\VObject; /** @@ -13,6 +14,8 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\FlatText TZID */ class VTimeZone extends VObject\Component { @@ -21,10 +24,8 @@ class VTimeZone extends VObject\Component * * If we can't accurately determine the timezone, this method will return * UTC. - * - * @return \DateTimeZone */ - public function getTimeZone() + public function getTimeZone(): \DateTimeZone { return VObject\TimeZoneUtil::getTimeZone((string) $this->TZID, $this->root); } @@ -41,10 +42,8 @@ public function getTimeZone() * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'TZID' => 1, diff --git a/lib/Component/VTodo.php b/lib/Component/VTodo.php index 6f022ba6d..bda49da74 100644 --- a/lib/Component/VTodo.php +++ b/lib/Component/VTodo.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeInterface; use Sabre\VObject; /** @@ -13,6 +12,19 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\ICalendar\DateTime DTSTART + * @property VObject\Property\ICalendar\DateTime DTEND + * @property VObject\Property\ICalendar\DateTime DTSTAMP + * @property VObject\Property\ICalendar\Duration DURATION + * @property VObject\Property\ICalendar\Recur RRULE + * @property VObject\Property\ICalendar\DateTime EXDATE + * @property VObject\Property\ICalendar\DateTime RDATE + * @property VObject\Property\ICalendar\Recur EXRULE + * @property VObject\Property\ICalendar\DateTime {'RECURRENCE-ID'} + * @property VObject\Property\ICalendar\DateTime DUE + * @property VObject\Property\ICalendar\DateTime COMPLETED + * @property VObject\Property\ICalendar\DateTime CREATED */ class VTodo extends VObject\Component { @@ -23,9 +35,9 @@ class VTodo extends VObject\Component * The rules used to determine if an event falls within the specified * time-range is based on the CalDAV specification. * - * @return bool + * @throws VObject\InvalidDataException */ - public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) + public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end): bool { $dtstart = isset($this->DTSTART) ? $this->DTSTART->getDateTime() : null; $duration = isset($this->DURATION) ? VObject\DateTimeParser::parseDuration($this->DURATION) : null; @@ -40,8 +52,8 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) return $start <= $effectiveEnd && $end > $dtstart; } elseif ($due) { return - ($start < $due || $start <= $dtstart) && - ($end > $dtstart || $end >= $due); + ($start < $due || $start <= $dtstart) + && ($end > $dtstart || $end >= $due); } else { return $start <= $dtstart && $end > $dtstart; } @@ -51,8 +63,8 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) } if ($completed && $created) { return - ($start <= $created || $start <= $completed) && - ($end >= $created || $end >= $completed); + ($start <= $created || $start <= $completed) + && ($end >= $created || $end >= $completed); } if ($completed) { return $start <= $completed && $end >= $completed; @@ -76,10 +88,8 @@ public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) * * + - Must appear at least once. * * * - Can appear any number of times. * * ? - May appear, but not more than once. - * - * @var array */ - public function getValidationRules() + public function getValidationRules(): array { return [ 'UID' => 1, @@ -137,11 +147,9 @@ public function getValidationRules() * 2 - An inconsequential issue * 3 - A severe issue. * - * @param int $options - * - * @return array + * @throws VObject\InvalidDataException */ - public function validate($options = 0) + public function validate(int $options = 0): array { $result = parent::validate($options); if (isset($this->DUE) && isset($this->DTSTART)) { @@ -168,10 +176,8 @@ public function validate($options = 0) /** * This method should return a list of default property values. - * - * @return array */ - protected function getDefaults() + protected function getDefaults(): array { return [ 'UID' => 'sabre-vobject-'.VObject\UUIDUtil::getUUID(), diff --git a/lib/DateTimeParser.php b/lib/DateTimeParser.php index 1c253437a..5ce9f207a 100644 --- a/lib/DateTimeParser.php +++ b/lib/DateTimeParser.php @@ -4,12 +4,11 @@ use DateInterval; use DateTimeImmutable; -use DateTimeZone; /** * DateTimeParser. * - * This class is responsible for parsing the several different date and time + * This class is responsible for parsing the several date and time * formats iCalendar and vCards have. * * @copyright Copyright (C) fruux GmbH (https://fruux.com/) @@ -26,12 +25,9 @@ class DateTimeParser * if the non-UTC format is used. The argument is used as a reference, the * returned DateTimeImmutable object will still be in the UTC timezone. * - * @param string $dt - * @param DateTimeZone $tz - * - * @return DateTimeImmutable + * @throws InvalidDataException */ - public static function parseDateTime($dt, DateTimeZone $tz = null) + public static function parseDateTime(string $dt, \DateTimeZone $tz = null): \DateTimeImmutable { // Format is YYYYMMDD + "T" + hhmmss $result = preg_match('/^([0-9]{4})([0-1][0-9])([0-3][0-9])T([0-2][0-9])([0-5][0-9])([0-5][0-9])([Z]?)$/', $dt, $matches); @@ -41,11 +37,11 @@ public static function parseDateTime($dt, DateTimeZone $tz = null) } if ('Z' === $matches[7] || is_null($tz)) { - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); } try { - $date = new DateTimeImmutable($matches[1].'-'.$matches[2].'-'.$matches[3].' '.$matches[4].':'.$matches[5].':'.$matches[6], $tz); + $date = new \DateTimeImmutable($matches[1].'-'.$matches[2].'-'.$matches[3].' '.$matches[4].':'.$matches[5].':'.$matches[6], $tz); } catch (\Exception $e) { throw new InvalidDataException('The supplied iCalendar datetime value is incorrect: '.$dt); } @@ -56,12 +52,9 @@ public static function parseDateTime($dt, DateTimeZone $tz = null) /** * Parses an iCalendar (rfc5545) formatted date and returns a DateTimeImmutable object. * - * @param string $date - * @param DateTimeZone $tz - * - * @return DateTimeImmutable + * @throws InvalidDataException */ - public static function parseDate($date, DateTimeZone $tz = null) + public static function parseDate(string $date, \DateTimeZone $tz = null): \DateTimeImmutable { // Format is YYYYMMDD $result = preg_match('/^([0-9]{4})([0-1][0-9])([0-3][0-9])$/', $date, $matches); @@ -71,11 +64,11 @@ public static function parseDate($date, DateTimeZone $tz = null) } if (is_null($tz)) { - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); } try { - $date = new DateTimeImmutable($matches[1].'-'.$matches[2].'-'.$matches[3], $tz); + $date = new \DateTimeImmutable($matches[1].'-'.$matches[2].'-'.$matches[3], $tz); } catch (\Exception $e) { throw new InvalidDataException('The supplied iCalendar date value is incorrect: '.$date); } @@ -86,29 +79,25 @@ public static function parseDate($date, DateTimeZone $tz = null) /** * Parses an iCalendar (RFC5545) formatted duration value. * - * This method will either return a DateTimeInterval object, or a string - * suitable for strtotime or DateTime::modify. - * - * @param string $duration - * @param bool $asString + * This method will return a DateTimeInterval object * - * @return DateInterval|string + * @throws InvalidDataException + * @throws \Exception */ - public static function parseDuration($duration, $asString = false) + public static function parseDuration(string $duration): \DateInterval { $result = preg_match('/^(?\+|-)?P((?\d+)W)?((?\d+)D)?(T((?\d+)H)?((?\d+)M)?((?\d+)S)?)?$/', $duration, $matches); if (!$result) { throw new InvalidDataException('The supplied iCalendar duration value is incorrect: '.$duration); } - if (!$asString) { - $invert = false; + $invert = false; - if ('-' === $matches['plusminus']) { - $invert = true; - } + if (isset($matches['plusminus']) && '-' === $matches['plusminus']) { + $invert = true; + } - $parts = [ + $parts = [ 'week', 'day', 'hour', @@ -116,50 +105,64 @@ public static function parseDuration($duration, $asString = false) 'second', ]; - foreach ($parts as $part) { - $matches[$part] = isset($matches[$part]) && $matches[$part] ? (int) $matches[$part] : 0; - } - - // We need to re-construct the $duration string, because weeks and - // days are not supported by DateInterval in the same string. - $duration = 'P'; - $days = $matches['day']; + foreach ($parts as $part) { + $matches[$part] = isset($matches[$part]) && $matches[$part] ? (int) $matches[$part] : 0; + } - if ($matches['week']) { - $days += $matches['week'] * 7; - } + // We need to re-construct the $duration string, because weeks and + // days are not supported by DateInterval in the same string. + $duration = 'P'; + $days = $matches['day']; - if ($days) { - $duration .= $days.'D'; - } + if ($matches['week']) { + $days += $matches['week'] * 7; + } - if ($matches['minute'] || $matches['second'] || $matches['hour']) { - $duration .= 'T'; + if ($days) { + $duration .= $days.'D'; + } - if ($matches['hour']) { - $duration .= $matches['hour'].'H'; - } + if ($matches['minute'] || $matches['second'] || $matches['hour']) { + $duration .= 'T'; - if ($matches['minute']) { - $duration .= $matches['minute'].'M'; - } + if ($matches['hour']) { + $duration .= $matches['hour'].'H'; + } - if ($matches['second']) { - $duration .= $matches['second'].'S'; - } + if ($matches['minute']) { + $duration .= $matches['minute'].'M'; } - if ('P' === $duration) { - $duration = 'PT0S'; + if ($matches['second']) { + $duration .= $matches['second'].'S'; } + } - $iv = new DateInterval($duration); + if ('P' === $duration) { + $duration = 'PT0S'; + } - if ($invert) { - $iv->invert = true; - } + $iv = new \DateInterval($duration); - return $iv; + if ($invert) { + $iv->invert = true; + } + + return $iv; + } + + /** + * Parses an iCalendar (RFC5545) formatted duration value. + * + * This method will return a string suitable for strtotime or DateTime::modify. + * + * @throws InvalidDataException + */ + public static function parseDurationAsString(string $duration): string + { + $result = preg_match('/^(?\+|-)?P((?\d+)W)?((?\d+)D)?(T((?\d+)H)?((?\d+)M)?((?\d+)S)?)?$/', $duration, $matches); + if (!$result) { + throw new InvalidDataException('The supplied iCalendar duration value is incorrect: '.$duration); } $parts = [ @@ -190,12 +193,13 @@ public static function parseDuration($duration, $asString = false) /** * Parses either a Date or DateTime, or Duration value. * - * @param string $date - * @param DateTimeZone|string $referenceTz + * @param \DateTimeZone|string $referenceTz * - * @return DateTimeImmutable|DateInterval + * @return \DateInterval|\DateTimeImmutable + * + * @throws InvalidDataException */ - public static function parse($date, $referenceTz = null) + public static function parse(string $date, $referenceTz = null) { if ('P' === $date[0] || ('-' === $date[0] && 'P' === $date[1])) { return self::parseDuration($date); @@ -258,11 +262,9 @@ public static function parse($date, $referenceTz = null) * Times may be postfixed by a timezone offset. This can be either 'Z' for * UTC, or a string like -0500 or +1100. * - * @param string $date - * - * @return array + * @throws InvalidDataException */ - public static function parseVCardDateTime($date) + public static function parseVCardDateTime(string $date): array { $regex = '/^ (?: # date part @@ -377,11 +379,9 @@ public static function parseVCardDateTime($date) * Times may be postfixed by a timezone offset. This can be either 'Z' for * UTC, or a string like -0500 or +11:00. * - * @param string $date - * - * @return array + * @throws InvalidDataException */ - public static function parseVCardTime($date) + public static function parseVCardTime(string $date): array { $regex = '/^ (? [0-9]{2} | -) @@ -483,11 +483,9 @@ public static function parseVCardTime($date) * Times may be postfixed by a timezone offset. This can be either 'Z' for * UTC, or a string like -0500 or +1100. * - * @param string $date - * - * @return array + * @throws InvalidDataException */ - public static function parseVCardDateAndOrTime($date) + public static function parseVCardDateAndOrTime(string $date): array { // \d{8}|\d{4}-\d\d|--\d\d(\d\d)?|---\d\d $valueDate = '/^(?J)(?:'. diff --git a/lib/Document.php b/lib/Document.php index 6265f34b5..2a249580b 100644 --- a/lib/Document.php +++ b/lib/Document.php @@ -2,6 +2,8 @@ namespace Sabre\VObject; +use Sabre\VObject; + /** * Document. * @@ -15,68 +17,62 @@ * @copyright Copyright (C) fruux GmbH (https://fruux.com/) * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License + * + * @property VObject\Property\FlatText VERSION */ abstract class Document extends Component { /** * Unknown document type. */ - const UNKNOWN = 1; + public const UNKNOWN = 1; /** * vCalendar 1.0. */ - const VCALENDAR10 = 2; + public const VCALENDAR10 = 2; /** * iCalendar 2.0. */ - const ICALENDAR20 = 3; + public const ICALENDAR20 = 3; /** * vCard 2.1. */ - const VCARD21 = 4; + public const VCARD21 = 4; /** * vCard 3.0. */ - const VCARD30 = 5; + public const VCARD30 = 5; /** * vCard 4.0. */ - const VCARD40 = 6; + public const VCARD40 = 6; /** * The default name for this component. * * This should be 'VCALENDAR' or 'VCARD'. - * - * @var string */ - public static $defaultName; + public static ?string $defaultName = null; /** * List of properties, and which classes they map to. - * - * @var array */ - public static $propertyMap = []; + public static array $propertyMap = []; /** * List of components, along with which classes they map to. - * - * @var array */ - public static $componentMap = []; + public static array $componentMap = []; /** * List of value-types, and which classes they map to. - * - * @var array */ - public static $valueMap = []; + public static array $valueMap = []; /** * Creates a new document. @@ -97,22 +93,20 @@ public function __construct() $args = func_get_args(); $name = static::$defaultName; if (0 === count($args) || is_array($args[0])) { - $children = isset($args[0]) ? $args[0] : []; - $defaults = isset($args[1]) ? $args[1] : true; + $children = $args[0] ?? []; + $defaults = $args[1] ?? true; } else { $name = $args[0]; - $children = isset($args[1]) ? $args[1] : []; - $defaults = isset($args[2]) ? $args[2] : true; + $children = $args[1] ?? []; + $defaults = $args[2] ?? true; } parent::__construct($this, $name, $children, $defaults); } /** * Returns the current document type. - * - * @return int */ - public function getDocumentType() + public function getDocumentType(): int { return self::UNKNOWN; } @@ -122,13 +116,8 @@ public function getDocumentType() * * If it's a known component, we will automatically call createComponent. * otherwise, we'll assume it's a property and call createProperty instead. - * - * @param string $name - * @param string $arg1,... Unlimited number of args - * - * @return mixed */ - public function create($name) + public function create(string $name) { if (isset(static::$componentMap[strtoupper($name)])) { return call_user_func_array([$this, 'createComponent'], func_get_args()); @@ -150,14 +139,8 @@ public function create($name) * By default, a set of sensible values will be added to the component. For * an iCalendar object, this may be something like CALSCALE:GREGORIAN. To * ensure that this does not happen, set $defaults to false. - * - * @param string $name - * @param array $children - * @param bool $defaults - * - * @return Component */ - public function createComponent($name, array $children = null, $defaults = true) + public function createComponent(string $name, array $children = null, bool $defaults = true): Component { $name = strtoupper($name); $class = Component::class; @@ -182,16 +165,13 @@ public function createComponent($name, array $children = null, $defaults = true) * parameters will automatically be created, or you can just pass a list of * Parameter objects. * - * @param string $name - * @param mixed $value - * @param array $parameters - * @param string $valueType Force a specific valuetype, such as URI or TEXT + * @param string|null $valueType Force a specific valueType, such as URI or TEXT * - * @return Property + * @throws InvalidDataException */ - public function createProperty($name, $value = null, array $parameters = null, $valueType = null) + public function createProperty(string $name, $value = null, array $parameters = null, string $valueType = null): Property { - // If there's a . in the name, it means it's prefixed by a groupname. + // If there's a . in the name, it means it's prefixed by a group name. if (false !== ($i = strpos($name, '.'))) { $group = substr($name, 0, $i); $name = strtoupper(substr($name, $i + 1)); @@ -237,11 +217,9 @@ public function createProperty($name, $value = null, array $parameters = null, $ * * This method returns null if we don't have a specialized class. * - * @param string $valueParam - * - * @return string|null + * @return string|void|null */ - public function getClassNameForPropertyValue($valueParam) + public function getClassNameForPropertyValue(string $valueParam) { $valueParam = strtoupper($valueParam); if (isset(static::$valueMap[$valueParam])) { @@ -251,17 +229,9 @@ public function getClassNameForPropertyValue($valueParam) /** * Returns the default class for a property name. - * - * @param string $propertyName - * - * @return string */ - public function getClassNameForPropertyName($propertyName) + public function getClassNameForPropertyName(string $propertyName): string { - if (isset(static::$propertyMap[$propertyName])) { - return static::$propertyMap[$propertyName]; - } else { - return Property\Unknown::class; - } + return static::$propertyMap[$propertyName] ?? Property\Unknown::class; } } diff --git a/lib/ElementList.php b/lib/ElementList.php index 860512649..9c81b7748 100644 --- a/lib/ElementList.php +++ b/lib/ElementList.php @@ -2,9 +2,6 @@ namespace Sabre\VObject; -use ArrayIterator; -use LogicException; - /** * VObject ElementList. * @@ -15,20 +12,19 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class ElementList extends ArrayIterator +class ElementList extends \ArrayIterator { /* {{{ ArrayAccess Interface */ /** * Sets an item through ArrayAccess. * - * @param int $offset - * @param mixed $value + * @param int $offset */ #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { - throw new LogicException('You can not add new objects to an ElementList'); + throw new \LogicException('You can not add new objects to an ElementList'); } /** @@ -39,9 +35,9 @@ public function offsetSet($offset, $value) * @param int $offset */ #[\ReturnTypeWillChange] - public function offsetUnset($offset) + public function offsetUnset($offset): void { - throw new LogicException('You can not remove objects from an ElementList'); + throw new \LogicException('You can not remove objects from an ElementList'); } /* }}} */ diff --git a/lib/FreeBusyData.php b/lib/FreeBusyData.php index 4d9f441ce..405a5886d 100644 --- a/lib/FreeBusyData.php +++ b/lib/FreeBusyData.php @@ -13,26 +13,20 @@ class FreeBusyData { /** * Start timestamp. - * - * @var int */ - protected $start; + protected int $start; /** * End timestamp. - * - * @var int */ - protected $end; + protected int $end; /** * A list of free-busy times. - * - * @var array */ - protected $data; + protected array $data; - public function __construct($start, $end) + public function __construct(int $start, int $end) { $this->start = $start; $this->end = $end; @@ -46,16 +40,14 @@ public function __construct($start, $end) } /** - * Adds free or busytime to the data. + * Adds free or busy time to the data. * - * @param int $start - * @param int $end - * @param string $type FREE, BUSY, BUSY-UNAVAILABLE or BUSY-TENTATIVE + * @param string $type FREE, BUSY, BUSY-UNAVAILABLE or BUSY-TENTATIVE */ - public function add($start, $end, $type) + public function add(int $start, int $end, string $type): void { if ($start > $this->end || $end < $this->start) { - // This new data is outside our timerange. + // This new data is outside our time range. return; } @@ -178,7 +170,7 @@ public function add($start, $end, $type) } } - public function getData() + public function getData(): array { return $this->data; } diff --git a/lib/FreeBusyGenerator.php b/lib/FreeBusyGenerator.php index 81b8126d5..2f222e4e5 100644 --- a/lib/FreeBusyGenerator.php +++ b/lib/FreeBusyGenerator.php @@ -2,10 +2,10 @@ namespace Sabre\VObject; -use DateTimeImmutable; -use DateTimeInterface; -use DateTimeZone; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; +use Sabre\VObject\Component\VFreeBusy; +use Sabre\VObject\Property\ICalendar\DateTime; use Sabre\VObject\Recur\EventIterator; use Sabre\VObject\Recur\NoInstancesException; @@ -27,31 +27,23 @@ class FreeBusyGenerator { /** * Input objects. - * - * @var array */ - protected $objects = []; + protected array $objects = []; /** * Start of range. - * - * @var DateTimeInterface|null */ - protected $start; + protected ?\DateTimeInterface $start; /** * End of range. - * - * @var DateTimeInterface|null */ - protected $end; + protected ?\DateTimeInterface $end; /** * VCALENDAR object. - * - * @var Document */ - protected $baseObject; + protected ?Document $baseObject = null; /** * Reference timezone. @@ -63,33 +55,24 @@ class FreeBusyGenerator * This is also used for all-day events. * * This defaults to UTC. - * - * @var DateTimeZone */ - protected $timeZone; + protected \DateTimeZone $timeZone; /** * A VAVAILABILITY document. * * If this is set, its information will be included when calculating * freebusy time. - * - * @var Document */ - protected $vavailability; + protected ?Document $vavailability = null; /** * Creates the generator. * * Check the setTimeRange and setObjects methods for details about the * arguments. - * - * @param DateTimeInterface $start - * @param DateTimeInterface $end - * @param mixed $objects - * @param DateTimeZone $timeZone */ - public function __construct(DateTimeInterface $start = null, DateTimeInterface $end = null, $objects = null, DateTimeZone $timeZone = null) + public function __construct(\DateTimeInterface $start = null, \DateTimeInterface $end = null, $objects = null, \DateTimeZone $timeZone = null) { $this->setTimeRange($start, $end); @@ -97,7 +80,7 @@ public function __construct(DateTimeInterface $start = null, DateTimeInterface $ $this->setObjects($objects); } if (is_null($timeZone)) { - $timeZone = new DateTimeZone('UTC'); + $timeZone = new \DateTimeZone('UTC'); } $this->setTimeZone($timeZone); } @@ -110,7 +93,7 @@ public function __construct(DateTimeInterface $start = null, DateTimeInterface $ * * The VFREEBUSY object will be automatically added though. */ - public function setBaseObject(Document $vcalendar) + public function setBaseObject(Document $vcalendar): void { $this->baseObject = $vcalendar; } @@ -118,7 +101,7 @@ public function setBaseObject(Document $vcalendar) /** * Sets a VAVAILABILITY document. */ - public function setVAvailability(Document $vcalendar) + public function setVAvailability(Document $vcalendar): void { $this->vavailability = $vcalendar; } @@ -129,10 +112,8 @@ public function setVAvailability(Document $vcalendar) * You must either specify a vcalendar object as a string, or as the parse * Component. * It's also possible to specify multiple objects as an array. - * - * @param mixed $objects */ - public function setObjects($objects) + public function setObjects($objects): void { if (!is_array($objects)) { $objects = [$objects]; @@ -153,18 +134,17 @@ public function setObjects($objects) /** * Sets the time range. * - * Any freebusy object falling outside of this time range will be ignored. + * Any freebusy object falling outside this time range will be ignored. * - * @param DateTimeInterface $start - * @param DateTimeInterface $end + * @throws \Exception */ - public function setTimeRange(DateTimeInterface $start = null, DateTimeInterface $end = null) + public function setTimeRange(\DateTimeInterface $start = null, \DateTimeInterface $end = null): void { if (!$start) { - $start = new DateTimeImmutable(Settings::$minDate); + $start = new \DateTimeImmutable(Settings::$minDate); } if (!$end) { - $end = new DateTimeImmutable(Settings::$maxDate); + $end = new \DateTimeImmutable(Settings::$maxDate); } $this->start = $start; $this->end = $end; @@ -173,7 +153,7 @@ public function setTimeRange(DateTimeInterface $start = null, DateTimeInterface /** * Sets the reference timezone for floating times. */ - public function setTimeZone(DateTimeZone $timeZone) + public function setTimeZone(\DateTimeZone $timeZone): void { $this->timeZone = $timeZone; } @@ -181,16 +161,14 @@ public function setTimeZone(DateTimeZone $timeZone) /** * Parses the input data and returns a correct VFREEBUSY object, wrapped in * a VCALENDAR. - * - * @return Component */ - public function getResult() + public function getResult(): Component { $fbData = new FreeBusyData( $this->start->getTimeStamp(), $this->end->getTimeStamp() ); - if ($this->vavailability) { + if (null !== $this->vavailability) { $this->calculateAvailability($fbData, $this->vavailability); } @@ -203,7 +181,7 @@ public function getResult() * This method takes a VAVAILABILITY component and figures out all the * available times. */ - protected function calculateAvailability(FreeBusyData $fbData, VCalendar $vavailability) + protected function calculateAvailability(FreeBusyData $fbData, VCalendar $vavailability): void { $vavailComps = iterator_to_array($vavailability->VAVAILABILITY); usort( @@ -231,7 +209,7 @@ function ($a, $b) { // Now we go over all the VAVAILABILITY components and figure if // there's any we don't need to consider. // - // This is can be because of one of two reasons: either the + // This is because of one of two reasons: either the // VAVAILABILITY component falls outside the time we are interested in, // or a different VAVAILABILITY component with a higher priority has // already completely covered the time-range. @@ -241,7 +219,7 @@ function ($a, $b) { foreach ($old as $vavail) { list($compStart, $compEnd) = $vavail->getEffectiveStartEnd(); - // We don't care about datetimes that are earlier or later than the + // We don't care about date-times that are earlier or later than the // start and end of the freebusy report, so this gets normalized // first. if (is_null($compStart) || $compStart < $this->start) { @@ -251,7 +229,7 @@ function ($a, $b) { $compEnd = $this->end; } - // If the item fell out of the timerange, we can just skip it. + // If the item fell out of the time range, we can just skip it. if ($compStart > $this->end || $compEnd < $this->start) { continue; } @@ -261,8 +239,8 @@ function ($a, $b) { foreach ($new as $higherVavail) { list($higherStart, $higherEnd) = $higherVavail->getEffectiveStartEnd(); if ( - (is_null($higherStart) || $higherStart < $compStart) && - (is_null($higherEnd) || $higherEnd > $compEnd) + (is_null($higherStart) || $higherStart < $compStart) + && (is_null($higherEnd) || $higherEnd > $compEnd) ) { // Component is fully covered by a higher priority // component. We can skip this component. @@ -305,18 +283,18 @@ function ($a, $b) { foreach ($vavail->AVAILABLE as $available) { list($availStart, $availEnd) = $available->getEffectiveStartEnd(); $fbData->add( - $availStart->getTimeStamp(), - $availEnd->getTimeStamp(), - 'FREE' - ); + $availStart->getTimeStamp(), + $availEnd->getTimeStamp(), + 'FREE' + ); if ($available->RRULE) { // Our favourite thing: recurrence!! $rruleIterator = new Recur\RRuleIterator( - $available->RRULE->getValue(), - $availStart - ); + $available->RRULE->getValue(), + $availStart + ); $rruleIterator->fastForward($vavailStart); $startEndDiff = $availStart->diff($availEnd); @@ -326,7 +304,7 @@ function ($a, $b) { $recurEnd = $recurStart->add($startEndDiff); if ($recurStart > $vavailEnd) { - // We're beyond the legal timerange. + // We're beyond the legal time range. break; } @@ -337,10 +315,10 @@ function ($a, $b) { } $fbData->add( - $recurStart->getTimeStamp(), - $recurEnd->getTimeStamp(), - 'FREE' - ); + $recurStart->getTimeStamp(), + $recurEnd->getTimeStamp(), + 'FREE' + ); $rruleIterator->next(); } @@ -355,13 +333,16 @@ function ($a, $b) { * times on fbData. * * @param VCalendar[] $objects + * + * @throws InvalidDataException|Recur\MaxInstancesExceededException */ - protected function calculateBusy(FreeBusyData $fbData, array $objects) + protected function calculateBusy(FreeBusyData $fbData, array $objects): void { foreach ($objects as $key => $object) { foreach ($object->getBaseComponents() as $component) { switch ($component->name) { case 'VEVENT': + /** @var VEvent $component */ $FBTYPE = 'BUSY'; if (isset($component->TRANSP) && ('TRANSPARENT' === strtoupper($component->TRANSP))) { break; @@ -447,6 +428,7 @@ protected function calculateBusy(FreeBusyData $fbData, array $objects) break; case 'VFREEBUSY': + /** @var VFreeBusy $component */ foreach ($component->FREEBUSY as $freebusy) { $fbType = isset($freebusy['FBTYPE']) ? strtoupper($freebusy['FBTYPE']) : 'BUSY'; @@ -491,11 +473,12 @@ protected function calculateBusy(FreeBusyData $fbData, array $objects) * This method takes a FreeBusyData object and generates the VCALENDAR * object associated with it. * - * @return VCalendar + * @throws InvalidDataException + * @throws \Exception */ - protected function generateFreeBusyCalendar(FreeBusyData $fbData) + protected function generateFreeBusyCalendar(FreeBusyData $fbData): VCalendar { - if ($this->baseObject) { + if (null !== $this->baseObject) { $calendar = $this->baseObject; } else { $calendar = new VCalendar(); @@ -505,19 +488,22 @@ protected function generateFreeBusyCalendar(FreeBusyData $fbData) $calendar->add($vfreebusy); if ($this->start) { + /** @var DateTime $dtstart */ $dtstart = $calendar->createProperty('DTSTART'); $dtstart->setDateTime($this->start); $vfreebusy->add($dtstart); } if ($this->end) { + /** @var DateTime $dtend */ $dtend = $calendar->createProperty('DTEND'); $dtend->setDateTime($this->end); $vfreebusy->add($dtend); } $tz = new \DateTimeZone('UTC'); + /** @var DateTime $dtstamp */ $dtstamp = $calendar->createProperty('DTSTAMP'); - $dtstamp->setDateTime(new DateTimeImmutable('now', $tz)); + $dtstamp->setDateTime(new \DateTimeImmutable('now', $tz)); $vfreebusy->add($dtstamp); foreach ($fbData->getData() as $busyTime) { diff --git a/lib/ITip/Broker.php b/lib/ITip/Broker.php index b66a59f54..f792fd990 100644 --- a/lib/ITip/Broker.php +++ b/lib/ITip/Broker.php @@ -3,9 +3,14 @@ namespace Sabre\VObject\ITip; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; +use Sabre\VObject\ParseException; use Sabre\VObject\Reader; use Sabre\VObject\Recur\EventIterator; +use Sabre\VObject\Recur\MaxInstancesExceededException; +use Sabre\VObject\Recur\NoInstancesException; /** * The ITip\Broker class is a utility class that helps with processing @@ -13,7 +18,7 @@ * * iTip is defined in rfc5546, stands for iCalendar Transport-Independent * Interoperability Protocol, and describes the underlying mechanism for - * using iCalendar for scheduling for for example through email (also known as + * using iCalendar for scheduling, for example, through email (also known as * IMip) and CalDAV Scheduling. * * This class helps by: @@ -27,7 +32,7 @@ * a received invite. * 4. It can also process an invite update on a local event, ensuring that any * overridden properties from attendees are retained. - * 5. It can create a accepted or declined iTip reply based on an invite. + * 5. It can create an accepted or declined iTip reply based on an invite. * 6. It can process a reply from an invite and update an events attendee * status based on a reply. * @@ -49,10 +54,8 @@ class Broker * CLIENT will be ignored. This is the desired behavior for a CalDAV * server, but if you're writing an iTip application that doesn't deal with * CalDAV, you may want to ignore this parameter. - * - * @var bool */ - public $scheduleAgentServerRules = true; + public bool $scheduleAgentServerRules = true; /** * The broker will try during 'parseEvent' figure out whether the change @@ -66,7 +69,7 @@ class Broker * * @var string[] */ - public $significantChangeProperties = [ + public array $significantChangeProperties = [ 'DTSTART', 'DTEND', 'DURATION', @@ -104,9 +107,11 @@ class Broker * * If the iTip message was not supported, we will always return false. * - * @param VCalendar $existingObject + * @return VCalendar|false|void|null * - * @return VCalendar|null + * @throws InvalidDataException + * @throws MaxInstancesExceededException + * @throws NoInstancesException */ public function processMessage(Message $itipMessage, VCalendar $existingObject = null) { @@ -129,8 +134,6 @@ public function processMessage(Message $itipMessage, VCalendar $existingObject = // Unsupported iTip message return; } - - return $existingObject; } /** @@ -156,13 +159,16 @@ public function processMessage(Message $itipMessage, VCalendar $existingObject = * people. If the user was an attendee, we need to make sure that the * organizer gets the 'declined' message. * - * @param VCalendar|string $calendar - * @param string|array $userHref - * @param VCalendar|string $oldCalendar + * @param VCalendar|string $calendar + * @param string|array $userHref + * @param VCalendar|string|null $oldCalendar * - * @return array + * @throws ITipException + * @throws InvalidDataException + * @throws ParseException + * @throws SameOrganizerForAllComponentsException */ - public function parseEvent($calendar, $userHref, $oldCalendar = null) + public function parseEvent($calendar, $userHref, $oldCalendar = null): array { if ($oldCalendar) { if (is_string($oldCalendar)) { @@ -216,7 +222,7 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null) // The calendar object got deleted, we need to process this as a // cancellation / decline. if (!$oldCalendar) { - // No old and no new calendar, there's no thing to do. + // No old and no new calendar, there's nothing to do. return []; } @@ -261,20 +267,13 @@ public function parseEvent($calendar, $userHref, $oldCalendar = null) * * This is message from an organizer, and is either a new event * invite, or an update to an existing one. - * - * @param VCalendar $existingObject - * - * @return VCalendar|null */ - protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null) + protected function processMessageRequest(Message $itipMessage, VCalendar $existingObject = null): ?VCalendar { if (!$existingObject) { // This is a new invite, and we're just going to copy over // all the components from the invite. $existingObject = new VCalendar(); - foreach ($itipMessage->message->getComponents() as $component) { - $existingObject->add(clone $component); - } } else { // We need to update an existing object with all the new // information. We can just remove all existing components @@ -282,9 +281,9 @@ protected function processMessageRequest(Message $itipMessage, VCalendar $existi foreach ($existingObject->getComponents() as $component) { $existingObject->remove($component); } - foreach ($itipMessage->message->getComponents() as $component) { - $existingObject->add(clone $component); - } + } + foreach ($itipMessage->message->getComponents() as $component) { + $existingObject->add(clone $component); } return $existingObject; @@ -296,12 +295,8 @@ protected function processMessageRequest(Message $itipMessage, VCalendar $existi * This is a message from an organizer, and means that either an * attendee got removed from an event, or an event got cancelled * altogether. - * - * @param VCalendar $existingObject - * - * @return VCalendar|null */ - protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject = null) + protected function processMessageCancel(Message $itipMessage, VCalendar $existingObject = null): ?VCalendar { if (!$existingObject) { // The event didn't exist in the first place, so we're just @@ -322,16 +317,16 @@ protected function processMessageCancel(Message $itipMessage, VCalendar $existin * The message is a reply. This is for example an attendee telling * an organizer he accepted the invite, or declined it. * - * @param VCalendar $existingObject - * - * @return VCalendar|null + * @throws InvalidDataException + * @throws MaxInstancesExceededException + * @throws NoInstancesException */ - protected function processMessageReply(Message $itipMessage, VCalendar $existingObject = null) + protected function processMessageReply(Message $itipMessage, VCalendar $existingObject = null): ?VCalendar { // A reply can only be processed based on an existing object. // If the object is not available, the reply is ignored. if (!$existingObject) { - return; + return null; } $instances = []; $requestStatus = '2.0'; @@ -386,7 +381,7 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing if (!$masterObject) { // No master object, we can't add new instances. - return; + return null; } // If we got replies to instances that did not exist in the // original list, it means that new exceptions must be created. @@ -446,10 +441,8 @@ protected function processMessageReply(Message $itipMessage, VCalendar $existing * * We will detect which attendees got added, which got removed and create * specific messages for these situations. - * - * @return array */ - protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, array $oldEventInfo) + protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, array $oldEventInfo): array { // Merging attendee lists. $attendees = []; @@ -511,6 +504,7 @@ protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, $icalMsg->METHOD = $message->method; + /** @var VEvent $event */ $event = $icalMsg->add('VEVENT', [ 'UID' => $message->uid, 'SEQUENCE' => $message->sequence, @@ -551,10 +545,10 @@ protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, $newAttendeeInstances = array_keys($attendee['newInstances']); $message->significantChange = - 'REQUEST' === $attendee['forceSend'] || - count($oldAttendeeInstances) != count($newAttendeeInstances) || - count(array_diff($oldAttendeeInstances, $newAttendeeInstances)) > 0 || - $oldEventInfo['significantChangeHash'] !== $eventInfo['significantChangeHash']; + 'REQUEST' === $attendee['forceSend'] + || count($oldAttendeeInstances) != count($newAttendeeInstances) + || count(array_diff($oldAttendeeInstances, $newAttendeeInstances)) > 0 + || $oldEventInfo['significantChangeHash'] !== $eventInfo['significantChangeHash']; foreach ($attendee['newInstances'] as $instanceId => $instanceInfo) { $currentEvent = clone $eventInfo['instances'][$instanceId]; @@ -615,11 +609,11 @@ protected function parseEventForOrganizer(VCalendar $calendar, array $eventInfo, * * This function figures out if we need to send a reply to an organizer. * - * @param string $attendee - * * @return Message[] + * + * @throws InvalidDataException */ - protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, array $oldEventInfo, $attendee) + protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, array $oldEventInfo, string $attendee): array { if ($this->scheduleAgentServerRules && 'CLIENT' === $eventInfo['organizerScheduleAgent']) { return []; @@ -710,6 +704,7 @@ protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, continue; } + /** @var VEvent $event */ $event = $icalMsg->add('VEVENT', [ 'UID' => $message->uid, 'SEQUENCE' => $message->sequence, @@ -796,11 +791,10 @@ protected function parseEventForAttendee(VCalendar $calendar, array $eventInfo, * 11. significantChangeHash * 12. status * - * @param VCalendar $calendar - * - * @return array + * @throws ITipException + * @throws SameOrganizerForAllComponentsException */ - protected function parseEventInfo(VCalendar $calendar = null) + protected function parseEventInfo(VCalendar $calendar): array { $uid = null; $organizer = null; @@ -811,8 +805,6 @@ protected function parseEventInfo(VCalendar $calendar = null) $status = null; $organizerScheduleAgent = 'SERVER'; - $significantChangeHash = ''; - // Now we need to collect a list of attendees, and which instances they // are a part of. $attendees = []; @@ -841,7 +833,7 @@ protected function parseEventInfo(VCalendar $calendar = null) if (isset($vevent->ORGANIZER)) { if (is_null($organizer)) { $organizer = $vevent->ORGANIZER->getNormalizedValue(); - $organizerName = isset($vevent->ORGANIZER['CN']) ? $vevent->ORGANIZER['CN'] : null; + $organizerName = $vevent->ORGANIZER['CN'] ?? null; } else { if (strtoupper($organizer) !== strtoupper($vevent->ORGANIZER->getNormalizedValue())) { throw new SameOrganizerForAllComponentsException('Every instance of the event must have the same organizer.'); @@ -894,9 +886,9 @@ protected function parseEventInfo(VCalendar $calendar = null) } if (isset($vevent->ATTENDEE)) { foreach ($vevent->ATTENDEE as $attendee) { - if ($this->scheduleAgentServerRules && - isset($attendee['SCHEDULE-AGENT']) && - 'CLIENT' === strtoupper($attendee['SCHEDULE-AGENT']->getValue()) + if ($this->scheduleAgentServerRules + && isset($attendee['SCHEDULE-AGENT']) + && 'CLIENT' === strtoupper($attendee['SCHEDULE-AGENT']->getValue()) ) { continue; } @@ -955,9 +947,7 @@ protected function parseEventInfo(VCalendar $calendar = null) asort($significantChangeEventProperties); - foreach ($significantChangeEventProperties as $eventSignificantChangeHash) { - $significantChangeHash .= $eventSignificantChangeHash; - } + $significantChangeHash = implode('', $significantChangeEventProperties); $significantChangeHash = md5($significantChangeHash); return compact( diff --git a/lib/ITip/ITipException.php b/lib/ITip/ITipException.php index 949563614..c949cdb7c 100644 --- a/lib/ITip/ITipException.php +++ b/lib/ITip/ITipException.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\ITip; -use Exception; - /** * This message is emitted in case of serious problems with iTip messages. * @@ -11,6 +9,6 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class ITipException extends Exception +class ITipException extends \Exception { } diff --git a/lib/ITip/Message.php b/lib/ITip/Message.php index 43536f172..9aa93996a 100644 --- a/lib/ITip/Message.php +++ b/lib/ITip/Message.php @@ -2,6 +2,8 @@ namespace Sabre\VObject\ITip; +use Sabre\VObject\Component\VCalendar; + /** * This class represents an iTip message. * @@ -18,32 +20,24 @@ class Message { /** * The object's UID. - * - * @var string */ - public $uid; + public string $uid; /** * The component type, such as VEVENT. - * - * @var string */ - public $component; + public string $component; /** * Contains the ITip method, which is something like REQUEST, REPLY or * CANCEL. - * - * @var string */ - public $method; + public ?string $method; /** * The current sequence number for the event. - * - * @var int */ - public $sequence; + public ?int $sequence; /** * The senders' email address. @@ -51,33 +45,25 @@ class Message * Note that this does not imply that this has to be used in a From: field * if the message is sent by email. It may also be populated in Reply-To: * or not at all. - * - * @var string */ - public $sender; + public string $sender; /** * The name of the sender. This is often populated from a CN parameter from * either the ORGANIZER or ATTENDEE, depending on the message. - * - * @var string|null */ - public $senderName; + public ?string $senderName; /** * The recipient's email address. - * - * @var string */ - public $recipient; + public string $recipient; /** * The name of the recipient. This is usually populated with the CN * parameter from the ATTENDEE or ORGANIZER property, if it's available. - * - * @var string|null */ - public $recipientName; + public ?string $recipientName; /** * After the message has been delivered, this should contain a string such @@ -87,17 +73,13 @@ class Message * * See: * http://tools.ietf.org/html/rfc6638#section-7.3 - * - * @var string */ - public $scheduleStatus; + public ?string $scheduleStatus = null; /** * The iCalendar / iTip body. - * - * @var \Sabre\VObject\Component\VCalendar */ - public $message; + public VCalendar $message; /** * This will be set to true, if the iTip broker considers the change @@ -110,10 +92,8 @@ class Message * * To see the list of properties that are considered 'significant', check * out Sabre\VObject\ITip\Broker::$significantChangeProperties. - * - * @var bool */ - public $significantChange = true; + public bool $significantChange = true; /** * Returns the schedule status as a string. diff --git a/lib/Node.php b/lib/Node.php index 2041b2ac7..0dbe7cfad 100644 --- a/lib/Node.php +++ b/lib/Node.php @@ -19,7 +19,7 @@ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \Js * If REPAIR is set, the validator will attempt to repair any broken data * (if possible). */ - const REPAIR = 1; + public const REPAIR = 1; /** * If this option is set, the validator will operate on the vcards on the @@ -28,7 +28,7 @@ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \Js * This means for example that the UID is required, whereas it is not for * regular vcards. */ - const PROFILE_CARDDAV = 2; + public const PROFILE_CARDDAV = 2; /** * If this option is set, the validator will operate on iCalendar objects @@ -37,41 +37,33 @@ abstract class Node implements \IteratorAggregate, \ArrayAccess, \Countable, \Js * This means for example that calendars can only contain objects with * identical component types and UIDs. */ - const PROFILE_CALDAV = 4; + public const PROFILE_CALDAV = 4; /** * Reference to the parent object, if this is not the top object. - * - * @var Node */ - public $parent; + public ?Node $parent; /** * Iterator override. - * - * @var ElementList */ - protected $iterator = null; + protected ?ElementList $iterator = null; /** * The root document. - * - * @var Component */ - protected $root; + protected ?Component $root; /** * Serializes the node into a mimedir format. - * - * @return string */ - abstract public function serialize(); + abstract public function serialize(): string; /** * This method returns an array, with the representation as it should be * encoded in JSON. This is used to create jCard or jCal documents. * - * @return array + * @return array|string */ #[\ReturnTypeWillChange] abstract public function jsonSerialize(); @@ -82,7 +74,7 @@ abstract public function jsonSerialize(); * * @param Xml\Writer $writer XML writer */ - abstract public function xmlSerialize(Xml\Writer $writer); + abstract public function xmlSerialize(Xml\Writer $writer): void; /** * Call this method on a document if you're done using it. @@ -90,7 +82,7 @@ abstract public function xmlSerialize(Xml\Writer $writer); * It's intended to remove all circular references, so PHP can easily clean * it up. */ - public function destroy() + public function destroy(): void { $this->parent = null; $this->root = null; @@ -100,11 +92,9 @@ public function destroy() /** * Returns the iterator for this object. - * - * @return ElementList */ #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): ?ElementList { if (!is_null($this->iterator)) { return $this->iterator; @@ -118,7 +108,7 @@ public function getIterator() * * Note that this is not actually part of the iterator interface */ - public function setIterator(ElementList $iterator) + public function setIterator(ElementList $iterator): void { $this->iterator = $iterator; } @@ -140,12 +130,8 @@ public function setIterator(ElementList $iterator) * 1 - The issue was repaired (only happens if REPAIR was turned on) * 2 - An inconsequential issue * 3 - A severe issue. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { return []; } @@ -156,11 +142,9 @@ public function validate($options = 0) /** * Returns the number of elements. - * - * @return int */ #[\ReturnTypeWillChange] - public function count() + public function count(): int { $it = $this->getIterator(); @@ -177,11 +161,9 @@ public function count() * This method just forwards the request to the inner iterator * * @param int $offset - * - * @return bool */ #[\ReturnTypeWillChange] - public function offsetExists($offset) + public function offsetExists($offset): bool { $iterator = $this->getIterator(); @@ -194,8 +176,6 @@ public function offsetExists($offset) * This method just forwards the request to the inner iterator * * @param int $offset - * - * @return mixed */ #[\ReturnTypeWillChange] public function offsetGet($offset) @@ -210,19 +190,18 @@ public function offsetGet($offset) * * This method just forwards the request to the inner iterator * - * @param int $offset - * @param mixed $value + * @param int $offset */ #[\ReturnTypeWillChange] - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { $iterator = $this->getIterator(); $iterator->offsetSet($offset, $value); // @codeCoverageIgnoreStart - // - // This method always throws an exception, so we ignore the closing - // brace + // + // This method always throws an exception, so we ignore the closing + // brace } // @codeCoverageIgnoreEnd @@ -235,15 +214,15 @@ public function offsetSet($offset, $value) * @param int $offset */ #[\ReturnTypeWillChange] - public function offsetUnset($offset) + public function offsetUnset($offset): void { $iterator = $this->getIterator(); $iterator->offsetUnset($offset); // @codeCoverageIgnoreStart - // - // This method always throws an exception, so we ignore the closing - // brace + // + // This method always throws an exception, so we ignore the closing + // brace } // @codeCoverageIgnoreEnd diff --git a/lib/PHPUnitAssertions.php b/lib/PHPUnitAssertions.php index 45c0a21c6..1976c3afd 100644 --- a/lib/PHPUnitAssertions.php +++ b/lib/PHPUnitAssertions.php @@ -30,9 +30,8 @@ trait PHPUnitAssertions * * @param resource|string|Component $expected * @param resource|string|Component $actual - * @param string $message */ - public function assertVObjectEqualsVObject($expected, $actual, $message = '') + public function assertVObjectEqualsVObject($expected, $actual, string $message = ''): void { $getObj = function ($input) { if (is_resource($input)) { diff --git a/lib/Parameter.php b/lib/Parameter.php index 5df6238e0..1ef7da88a 100644 --- a/lib/Parameter.php +++ b/lib/Parameter.php @@ -2,7 +2,6 @@ namespace Sabre\VObject; -use ArrayIterator; use Sabre\Xml; /** @@ -21,24 +20,20 @@ class Parameter extends Node { /** * Parameter name. - * - * @var string */ - public $name; + public string $name; /** * vCard 2.1 allows parameters to be encoded without a name. * * We can deduce the parameter name based on its value. - * - * @var bool */ - public $noName = false; + public bool $noName = false; /** * Parameter value. * - * @var string + * @var string|array|null */ protected $value; @@ -47,16 +42,17 @@ class Parameter extends Node * * It's recommended to use the create:: factory method instead. * - * @param string|null $name - * @param string $value + * @param string|array|null $value */ - public function __construct(Document $root, $name, $value = null) + public function __construct(Document $root, ?string $name, $value = null) { $this->name = is_null($name) ? '' : strtoupper($name); $this->root = $root; if (is_null($name)) { $this->noName = true; $this->name = static::guessParameterNameByValue($value); + } else { + $this->name = strtoupper($name); } // If guessParameterNameByValue() returns an empty string @@ -76,12 +72,8 @@ public function __construct(Document $root, $name, $value = null) * Figuring out what the name should have been. Note that a ton of * these are rather silly in 2014 and would probably rarely be * used, but we like to be complete. - * - * @param string $value - * - * @return string */ - public static function guessParameterNameByValue($value) + public static function guessParameterNameByValue(string $value): string { switch (strtoupper($value)) { // Encodings @@ -91,16 +83,16 @@ public static function guessParameterNameByValue($value) $name = 'ENCODING'; break; - // Common types + // Common types case 'WORK': case 'HOME': case 'PREF': - // Delivery Label Type + // Delivery Label Type case 'DOM': case 'INTL': case 'POSTAL': case 'PARCEL': - // Telephone types + // Telephone types case 'VOICE': case 'FAX': case 'MSG': @@ -111,7 +103,7 @@ public static function guessParameterNameByValue($value) case 'CAR': case 'ISDN': case 'VIDEO': - // EMAIL types (lol) + // EMAIL types (lol) case 'AOL': case 'APPLELINK': case 'ATTMAIL': @@ -124,7 +116,7 @@ public static function guessParameterNameByValue($value) case 'PRODIGY': case 'TLX': case 'X400': - // Photo / Logo format types + // Photo / Logo format types case 'GIF': case 'CGM': case 'WMF': @@ -139,17 +131,17 @@ public static function guessParameterNameByValue($value) case 'MPEG2': case 'AVI': case 'QTIME': - // Sound Digital Audio Type + // Sound Digital Audio Type case 'WAVE': case 'PCM': case 'AIFF': - // Key types + // Key types case 'X509': case 'PGP': $name = 'TYPE'; break; - // Value types + // Value types case 'INLINE': case 'URL': case 'CONTENT-ID': @@ -171,7 +163,7 @@ public static function guessParameterNameByValue($value) * * @param string|array $value */ - public function setValue($value) + public function setValue($value): void { $this->value = $value; } @@ -181,10 +173,8 @@ public function setValue($value) * * This method will always return a string, or null. If there were multiple * values, it will automatically concatenate them (separated by comma). - * - * @return string|null */ - public function getValue() + public function getValue(): ?string { if (is_array($this->value)) { return implode(',', $this->value); @@ -196,7 +186,7 @@ public function getValue() /** * Sets multiple values for this parameter. */ - public function setParts(array $value) + public function setParts(array $value): void { $this->value = $value; } @@ -205,10 +195,8 @@ public function setParts(array $value) * Returns all values for this parameter. * * If there were no values, an empty array will be returned. - * - * @return array */ - public function getParts() + public function getParts(): array { if (is_array($this->value)) { return $this->value; @@ -227,7 +215,7 @@ public function getParts() * * @param string|array $part */ - public function addValue($part) + public function addValue($part): void { if (is_null($this->value)) { $this->value = $part; @@ -239,15 +227,11 @@ public function addValue($part) /** * Checks if this parameter contains the specified value. * - * This is a case-insensitive match. It makes sense to call this for for - * instance the TYPE parameter, to see if it contains a keyword such as + * This is a case-insensitive match. It makes sense to call this for + * the TYPE parameter, for instance, to see if it contains a keyword such as * 'WORK' or 'FAX'. - * - * @param string $value - * - * @return bool */ - public function has($value) + public function has(string $value): bool { return in_array( strtolower($value), @@ -257,10 +241,8 @@ public function has($value) /** * Turns the object back into a serialized blob. - * - * @return string */ - public function serialize() + public function serialize(): string { $value = $this->getParts(); @@ -319,7 +301,7 @@ function ($out, $item) { * This method returns an array, with the representation as it should be * encoded in JSON. This is used to create jCard or jCal documents. * - * @return array + * @return array|string|null */ #[\ReturnTypeWillChange] public function jsonSerialize() @@ -333,7 +315,7 @@ public function jsonSerialize() * * @param Xml\Writer $writer XML writer */ - public function xmlSerialize(Xml\Writer $writer) + public function xmlSerialize(Xml\Writer $writer): void { foreach (explode(',', $this->value) as $value) { $writer->writeElement('text', $value); @@ -342,26 +324,22 @@ public function xmlSerialize(Xml\Writer $writer) /** * Called when this object is being cast to a string. - * - * @return string */ - public function __toString() + public function __toString(): string { return (string) $this->getValue(); } /** * Returns the iterator for this object. - * - * @return ElementList */ #[\ReturnTypeWillChange] - public function getIterator() + public function getIterator(): ElementList { if (!is_null($this->iterator)) { return $this->iterator; } - return $this->iterator = new ArrayIterator((array) $this->value); + return $this->iterator = new ElementList((array) $this->value); } } diff --git a/lib/Parser/Json.php b/lib/Parser/Json.php index f33603207..df87114a1 100644 --- a/lib/Parser/Json.php +++ b/lib/Parser/Json.php @@ -2,11 +2,14 @@ namespace Sabre\VObject\Parser; +use Sabre\VObject\Component; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCard; use Sabre\VObject\Document; use Sabre\VObject\EofException; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\ParseException; +use Sabre\VObject\Property; use Sabre\VObject\Property\FlatText; use Sabre\VObject\Property\Text; @@ -23,17 +26,13 @@ class Json extends Parser { /** * The input data. - * - * @var array */ - protected $input; + protected ?array $input; /** * Root component. - * - * @var Document */ - protected $root; + protected ?Document $root; /** * This method starts the parsing process. @@ -44,11 +43,12 @@ class Json extends Parser * If either input or options are not supplied, the defaults will be used. * * @param resource|string|array|null $input - * @param int $options * - * @return \Sabre\VObject\Document + * @throws EofException + * @throws ParseException + * @throws InvalidDataException */ - public function parse($input = null, $options = 0) + public function parse($input = null, int $options = 0): ?Document { if (!is_null($input)) { $this->setInput($input); @@ -80,7 +80,7 @@ public function parse($input = null, $options = 0) } } - // Resetting the input so we can throw an feof exception the next time. + // Resetting the input so that we can throw an feof exception the next time. $this->input = null; return $this->root; @@ -89,9 +89,9 @@ public function parse($input = null, $options = 0) /** * Parses a component. * - * @return \Sabre\VObject\Component + * @throws InvalidDataException */ - public function parseComponent(array $jComp) + public function parseComponent(array $jComp): Component { // We can remove $self from PHP 5.4 onward. $self = $this; @@ -117,16 +117,16 @@ function ($jComp) use ($self) { return $this->root->createComponent( $jComp[0], array_merge($properties, $components), - $defaults = false + false ); } /** * Parses properties. * - * @return \Sabre\VObject\Property + * @throws InvalidDataException */ - public function parseProperty(array $jProp) + public function parseProperty(array $jProp): Property { list( $propertyName, @@ -177,7 +177,7 @@ public function parseProperty(array $jProp) * * @param resource|string|array $input */ - public function setInput($input) + public function setInput($input): void { if (is_resource($input)) { $input = stream_get_contents($input); diff --git a/lib/Parser/MimeDir.php b/lib/Parser/MimeDir.php index b0b52d223..1ba2f1c59 100644 --- a/lib/Parser/MimeDir.php +++ b/lib/Parser/MimeDir.php @@ -2,13 +2,14 @@ namespace Sabre\VObject\Parser; -use Sabre\VObject\Component; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCard; use Sabre\VObject\Document; use Sabre\VObject\EofException; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Node; use Sabre\VObject\ParseException; +use Sabre\VObject\Property; use Sabre\VObject\Reader; /** @@ -35,13 +36,11 @@ class MimeDir extends Parser /** * Root component. - * - * @var Component */ - protected $root; + protected ?Document $root; /** - * By default all input will be assumed to be UTF-8. + * By default, all input will be assumed to be UTF-8. * * However, both iCalendar and vCard might be encoded using different * character sets. The character set is usually set in the mime-type. @@ -49,17 +48,15 @@ class MimeDir extends Parser * If this is the case, use setEncoding to specify that a different * encoding will be used. If this is set, the parser will automatically * convert all incoming data to UTF-8. - * - * @var string */ - protected $charset = 'UTF-8'; + protected string $charset = 'UTF-8'; /** * The list of character sets we support when decoding. * * This would be a const expression but for now we need to support PHP 5.5 */ - protected static $SUPPORTED_CHARSETS = [ + protected static array $SUPPORTED_CHARSETS = [ 'UTF-8', 'ISO-8859-1', 'Windows-1252', @@ -72,15 +69,14 @@ class MimeDir extends Parser * used. * * @param string|resource|null $input - * @param int $options * - * @return \Sabre\VObject\Document + * @throws ParseException */ - public function parse($input = null, $options = 0) + public function parse($input = null, int $options = 0): ?Document { $this->root = null; - if (!is_null($input)) { + if (!\is_null($input)) { $this->setInput($input); } @@ -94,7 +90,7 @@ public function parse($input = null, $options = 0) } /** - * By default all input will be assumed to be UTF-8. + * By default, all input will be assumed to be UTF-8. * * However, both iCalendar and vCard might be encoded using different * character sets. The character set is usually set in the mime-type. @@ -102,10 +98,8 @@ public function parse($input = null, $options = 0) * If this is the case, use setEncoding to specify that a different * encoding will be used. If this is set, the parser will automatically * convert all incoming data to UTF-8. - * - * @param string $charset */ - public function setCharset($charset) + public function setCharset(string $charset): void { if (!in_array($charset, self::$SUPPORTED_CHARSETS)) { throw new \InvalidArgumentException('Unsupported encoding. (Supported encodings: '.implode(', ', self::$SUPPORTED_CHARSETS).')'); @@ -117,6 +111,8 @@ public function setCharset($charset) * Sets the input buffer. Must be a string or stream. * * @param resource|string $input + * + * @return void */ public function setInput($input) { @@ -139,18 +135,21 @@ public function setInput($input) /** * Parses an entire document. + * + * @throws EofException + * @throws ParseException */ - protected function parseDocument() + protected function parseDocument(): void { $line = $this->readLine(); // BOM is ZERO WIDTH NO-BREAK SPACE (U+FEFF). // It's 0xEF 0xBB 0xBF in UTF-8 hex. if (3 <= strlen($line) - && 0xef === ord($line[0]) - && 0xbb === ord($line[1]) - && 0xbf === ord($line[2])) { - $line = substr($line, 3); + && 0xEF === ord($line[0]) + && 0xBB === ord($line[1]) + && 0xBF === ord($line[2])) { + $line = \substr($line, 3); } switch (strtoupper($line)) { @@ -168,8 +167,12 @@ protected function parseDocument() while (true) { // Reading until we hit END: - $line = $this->readLine(); - if ('END:' === strtoupper(substr($line, 0, 4))) { + try { + $line = $this->readLine(); + } catch (EofException $oEx) { + $line = 'END:'.$this->root->name; + } + if ('END:' === strtoupper(\substr($line, 0, 4))) { break; } $result = $this->parseLine($line); @@ -178,7 +181,7 @@ protected function parseDocument() } } - $name = strtoupper(substr($line, 4)); + $name = strtoupper(\substr($line, 4)); if ($name !== $this->root->name) { throw new ParseException('Invalid MimeDir file. expected: "END:'.$this->root->name.'" got: "END:'.$name.'"'); } @@ -190,22 +193,25 @@ protected function parseDocument() * * @param string $line Unfolded line * - * @return Node + * @return Node|Property|false + * + * @throws EofException + * @throws ParseException */ - protected function parseLine($line) + protected function parseLine(string $line) { // Start of a new component - if ('BEGIN:' === strtoupper(substr($line, 0, 6))) { - if (substr($line, 6) === $this->root->name) { + if ('BEGIN:' === strtoupper(\substr($line, 0, 6))) { + if (\substr($line, 6) === $this->root->name) { throw new ParseException('Invalid MimeDir file. Unexpected component: "'.$line.'" in document type '.$this->root->name); } - $component = $this->root->createComponent(substr($line, 6), [], false); + $component = $this->root->createComponent(\substr($line, 6), [], false); $prevNode = null; while (true) { // Reading until we hit END: $line = $this->readLine(); - if ('END:' === strtoupper(substr($line, 0, 4))) { + if ('END:' === strtoupper(\substr($line, 0, 4))) { break; } try { @@ -217,7 +223,7 @@ protected function parseLine($line) ) { // Fix unfolding $component->remove($prevNode); - $value = $prevNode->getValue() . ' ' . $line . PHP_EOL; + $value = $prevNode->getValue().' '.$line.PHP_EOL; $prevNode->offsetSet('VALUE', $value); $prevNode->setValue($value); $component->add($prevNode); @@ -230,7 +236,7 @@ protected function parseLine($line) } } - $name = strtoupper(substr($line, 4)); + $name = strtoupper(\substr($line, 4)); if ($name !== $component->name) { throw new ParseException('Invalid MimeDir file. expected: "END:'.$component->name.'" got: "END:'.$name.'"'); } @@ -253,41 +259,33 @@ protected function parseLine($line) * the next line. * * If that was not the case, we store it here. - * - * @var string|null */ - protected $lineBuffer; + protected ?string $lineBuffer = null; /** * The real current line number. */ - protected $lineIndex = 0; + protected int $lineIndex = 0; /** * In the case of unfolded lines, this property holds the line number for * the start of the line. - * - * @var int */ - protected $startLine = 0; + protected int $startLine = 0; /** * Contains a 'raw' representation of the current line. - * - * @var string */ - protected $rawLine; + protected string $rawLine; /** * Reads a single line from the buffer. * * This method strips any newlines and also takes care of unfolding. * - * @throws \Sabre\VObject\EofException - * - * @return string + * @throws EofException|ParseException */ - protected function readLine() + protected function readLine(): ?string { if (!\is_null($this->lineBuffer)) { $rawLine = $this->lineBuffer; @@ -335,8 +333,12 @@ protected function readLine() /** * Reads a property or component from a line. + * + * @return Property|false + * + * @throws ParseException|InvalidDataException */ - protected function readProperty($line) + protected function readProperty(string $line) { if ($this->options & self::OPTION_FORGIVING) { $propNameToken = 'A-Z0-9\-\._\\/'; @@ -361,7 +363,7 @@ protected function readProperty($line) ) (?=[;:,]) /xi"; - //echo $regex, "\n"; exit(); + // echo $regex, "\n"; exit(); preg_match_all($regex, $line, $matches, PREG_SET_ORDER); $property = [ @@ -382,21 +384,31 @@ protected function readProperty($line) foreach ($matches as $match) { if (isset($match['paramValue'])) { if ($match['paramValue'] && '"' === $match['paramValue'][0]) { - $value = substr($match['paramValue'], 1, -1); + $value = \substr($match['paramValue'], 1, -1); } else { $value = $match['paramValue']; } $value = $this->unescapeParam($value); - if (is_null($lastParam)) { + if (\is_null($lastParam)) { + if ($this->options & self::OPTION_IGNORE_INVALID_LINES) { + // When the property can't be matched and the configuration + // option is set to ignore invalid lines, we ignore this line + // This can happen when servers provide faulty data as iCloud + // frequently does with X-APPLE-STRUCTURED-LOCATION + continue; + } throw new ParseException('Invalid Mimedir file. Line starting at '.$this->startLine.' did not follow iCalendar/vCard conventions'); } - if (is_null($property['parameters'][$lastParam])) { + if (\is_null($property['parameters'][$lastParam])) { $property['parameters'][$lastParam] = $value; } elseif (is_array($property['parameters'][$lastParam])) { $property['parameters'][$lastParam][] = $value; - } elseif ($property['parameters'][$lastParam] !== $value) { + } elseif ($property['parameters'][$lastParam] === $value) { + // When the current value of the parameter is the same as the + // new one, then we can leave the current parameter as it is. + } else { $property['parameters'][$lastParam] = [ $property['parameters'][$lastParam], $value, @@ -425,7 +437,7 @@ protected function readProperty($line) // @codeCoverageIgnoreEnd } - if (is_null($property['value'])) { + if (\is_null($property['value'])) { $property['value'] = ''; } if (!$property['name']) { @@ -444,7 +456,7 @@ protected function readProperty($line) $namelessParameters = []; foreach ($property['parameters'] as $name => $value) { - if (!is_null($value)) { + if (!\is_null($value)) { $namedParameters[$name] = $value; } else { $namelessParameters[] = $name; @@ -458,6 +470,7 @@ protected function readProperty($line) } if (isset($propObj['ENCODING']) && 'QUOTED-PRINTABLE' === strtoupper($propObj['ENCODING'])) { + /* @var Property\Text|Property\FlatText $propObj */ $propObj->setQuotedPrintableValue($this->extractQuotedPrintableValue()); } else { $charset = $this->charset; @@ -468,10 +481,8 @@ protected function readProperty($line) switch (strtolower($charset)) { case 'utf-8': break; - case 'iso-8859-1': - $property['value'] = utf8_encode($property['value']); - break; case 'windows-1252': + case 'iso-8859-1': $property['value'] = mb_convert_encoding($property['value'], 'UTF-8', $charset); break; default: @@ -489,7 +500,7 @@ protected function readProperty($line) * vCard 2.1 says: * * Semi-colons must be escaped in some property values, specifically * ADR, ORG and N. - * * Semi-colons must be escaped in parameter values, because semi-colons + * * Semi-colons must be escaped in parameter values, because semicolons * are also use to separate values. * * No mention of escaping backslashes with another backslash. * * newlines are not escaped either, instead QUOTED-PRINTABLE is used to @@ -497,10 +508,10 @@ protected function readProperty($line) * * vCard 3.0 says: * * (rfc2425) Backslashes, newlines (\n or \N) and comma's must be - * escaped, all time time. - * * Comma's are used for delimiters in multiple values - * * (rfc2426) Adds to to this that the semi-colon MUST also be escaped, - * as in some properties semi-colon is used for separators. + * escaped, all the time. + * * Commas are used for delimiters in multiple values + * * (rfc2426) Adds to this that the semicolon MUST also be escaped, + * as in some properties semicolon is used for separators. * * Properties using semi-colons: N, ADR, GEO, ORG * * Both ADR and N's individual parts may be broken up further with a * comma. @@ -508,12 +519,12 @@ protected function readProperty($line) * * vCard 4.0 (rfc6350) says: * * Commas must be escaped. - * * Semi-colons may be escaped, an unescaped semi-colon _may_ be a + * * Semi-colons may be escaped, an unescaped semicolon _may_ be a * delimiter, depending on the property. * * Backslashes must be escaped * * Newlines must be escaped as either \N or \n. * * Some compound properties may contain multiple parts themselves, so a - * comma within a semi-colon delimited property may also be unescaped + * comma within a semicolon delimited property may also be unescaped * to denote multiple parts _within_ the compound property. * * Text-properties using semi-colons: N, ADR, ORG, CLIENTPIDMAP. * * Text-properties using commas: NICKNAME, RELATED, CATEGORIES, PID. @@ -522,7 +533,7 @@ protected function readProperty($line) * example for GEO in Section 6.5.2 seems to violate this. * * iCalendar 2.0 (rfc5545) says: - * * Commas or semi-colons may be used as delimiters, depending on the + * * Commas or semicolons may be used as delimiters, depending on the * property. * * Commas, semi-colons, backslashes, newline (\N or \n) are always * escaped, unless they are delimiters. @@ -532,20 +543,17 @@ protected function readProperty($line) * insignificant. * * Semi-colons are described as the delimiter for 'structured values'. * They are specifically used in Semi-colons are used as a delimiter in - * REQUEST-STATUS, RRULE, GEO and EXRULE. EXRULE is deprecated however. + * REQUEST-STATUS, RRULE, GEO and EXRULE. EXRULE is deprecated, however. * * Now for the parameters * * If delimiter is not set (empty string) this method will just return a string. - * If it's a comma or a semi-colon the string will be split on those + * If it's a comma or a semicolon the string will be split on those * characters, and always return an array. * - * @param string $input - * @param string $delimiter - * * @return string|string[] */ - public static function unescapeValue($input, $delimiter = ';') + public static function unescapeValue(string $input, string $delimiter = ';') { $regex = '# (?: (\\\\ (?: \\\\ | N | n | ; | , ) )'; if ($delimiter) { @@ -595,11 +603,11 @@ public static function unescapeValue($input, $delimiter = ';') * * Does not mention a mechanism for this. In addition, double quotes * are never used to wrap values. * * This means that parameters can simply not contain colons or - * semi-colons. + * semicolons. * * vCard 3.0 (rfc2425, rfc2426): * * Parameters _may_ be surrounded by double quotes. - * * If this is not the case, semi-colon, colon and comma may simply not + * * If this is not the case, semicolon, colon and comma may simply not * occur (the comma used for multiple parameter values though). * * If it is surrounded by double-quotes, it may simply not contain * double-quotes. @@ -617,10 +625,8 @@ public static function unescapeValue($input, $delimiter = ';') * * New-line is encoded as ^n * * ^ is encoded as ^^. * * " is encoded as ^' - * - * @param string $input */ - private function unescapeParam($input) + private function unescapeParam(string $input): ?string { return preg_replace_callback( @@ -634,7 +640,7 @@ function ($matches) { case '\'': return '"'; - // @codeCoverageIgnoreStart + // @codeCoverageIgnoreStart } // @codeCoverageIgnoreEnd }, @@ -650,9 +656,10 @@ function ($matches) { * * This method does not do any decoding. * - * @return string + * @throws EofException + * @throws ParseException */ - private function extractQuotedPrintableValue() + private function extractQuotedPrintableValue(): string { // We need to parse the raw line again to get the start of the value. // @@ -672,11 +679,11 @@ private function extractQuotedPrintableValue() // like unfolding, but we keep the newline. $value = str_replace("\n ", "\n", $value); - // Microsoft products don't always correctly fold lines, they may be + // Microsoft's products don't always correctly fold lines, they may be // missing a whitespace. So if 'forgiving' is turned on, we will take // those as well. if ($this->options & self::OPTION_FORGIVING) { - while ('=' === substr($value, -1) && $this->lineBuffer) { + while ('=' === \substr($value, -1) && $this->lineBuffer) { // Reading the line $this->readLine(); // Grabbing the raw form diff --git a/lib/Parser/Parser.php b/lib/Parser/Parser.php index b7b611430..29921d182 100644 --- a/lib/Parser/Parser.php +++ b/lib/Parser/Parser.php @@ -2,6 +2,8 @@ namespace Sabre\VObject\Parser; +use Sabre\VObject\Document; + /** * Abstract parser. * @@ -20,30 +22,27 @@ abstract class Parser * accept slashes and underscores in property names, and it will also * attempt to fix Microsoft vCard 2.1's broken line folding. */ - const OPTION_FORGIVING = 1; + public const OPTION_FORGIVING = 1; /** * If this option is turned on, any lines we cannot parse will be ignored * by the reader. */ - const OPTION_IGNORE_INVALID_LINES = 2; + public const OPTION_IGNORE_INVALID_LINES = 2; /** * Bitmask of parser options. - * - * @var int */ - protected $options; + protected int $options; /** * Creates the parser. * * Optionally, it's possible to parse the input stream here. * - * @param mixed $input - * @param int $options any parser options (OPTION constants) + * @param int $options any parser options (OPTION constants) */ - public function __construct($input = null, $options = 0) + public function __construct($input = null, int $options = 0) { if (!is_null($input)) { $this->setInput($input); @@ -59,17 +58,14 @@ public function __construct($input = null, $options = 0) * * If either input or options are not supplied, the defaults will be used. * - * @param mixed $input - * @param int $options - * - * @return array + * @param resource|string|array|null $input */ - abstract public function parse($input = null, $options = 0); + abstract public function parse($input = null, int $options = 0): ?Document; /** * Sets the input data. * - * @param mixed $input + * @param resource|string|array $input */ abstract public function setInput($input); } diff --git a/lib/Parser/XML.php b/lib/Parser/XML.php index 78773173d..9a5100684 100644 --- a/lib/Parser/XML.php +++ b/lib/Parser/XML.php @@ -5,7 +5,9 @@ use Sabre\VObject\Component; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Component\VCard; +use Sabre\VObject\Document; use Sabre\VObject\EofException; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\ParseException; use Sabre\Xml as SabreXml; @@ -20,39 +22,32 @@ */ class XML extends Parser { - const XCAL_NAMESPACE = 'urn:ietf:params:xml:ns:icalendar-2.0'; - const XCARD_NAMESPACE = 'urn:ietf:params:xml:ns:vcard-4.0'; + public const XCAL_NAMESPACE = 'urn:ietf:params:xml:ns:icalendar-2.0'; + public const XCARD_NAMESPACE = 'urn:ietf:params:xml:ns:vcard-4.0'; /** * The input data. - * - * @var array */ - protected $input; + protected ?array $input; /** * A pointer/reference to the input. - * - * @var array */ - private $pointer; + private ?array $pointer; /** * Document, root component. - * - * @var \Sabre\VObject\Document */ - protected $root; + protected ?Document $root; /** * Creates the parser. * * Optionally, it's possible to parse the input stream here. * - * @param mixed $input - * @param int $options any parser options (OPTION constants) + * @param int $options any parser options (OPTION constants) */ - public function __construct($input = null, $options = 0) + public function __construct($input = null, int $options = 0) { if (0 === $options) { $options = parent::OPTION_FORGIVING; @@ -64,14 +59,14 @@ public function __construct($input = null, $options = 0) /** * Parse xCal or xCard. * - * @param resource|string $input - * @param int $options + * @param resource|string|null $input * - * @throws \Exception - * - * @return \Sabre\VObject\Document + * @throws EofException + * @throws InvalidDataException + * @throws ParseException + * @throws SabreXml\LibXMLException */ - public function parse($input = null, $options = 0) + public function parse($input = null, int $options = 0): ?Document { if (!is_null($input)) { $this->setInput($input); @@ -112,8 +107,10 @@ public function parse($input = null, $options = 0) /** * Parse a xCalendar component. + * + * @throws InvalidDataException */ - protected function parseVCalendarComponents(Component $parentComponent) + protected function parseVCalendarComponents(Component $parentComponent): void { foreach ($this->pointer['value'] ?: [] as $children) { switch (static::getTagName($children['name'])) { @@ -132,8 +129,10 @@ protected function parseVCalendarComponents(Component $parentComponent) /** * Parse a xCard component. + * + * @throws InvalidDataException */ - protected function parseVCardComponents(Component $parentComponent) + protected function parseVCardComponents(Component $parentComponent): void { $this->pointer = &$this->pointer['value']; $this->parseProperties($parentComponent); @@ -142,9 +141,9 @@ protected function parseVCardComponents(Component $parentComponent) /** * Parse xCalendar and xCard properties. * - * @param string $propertyNamePrefix + * @throws InvalidDataException */ - protected function parseProperties(Component $parentComponent, $propertyNamePrefix = '') + protected function parseProperties(Component $parentComponent, string $propertyNamePrefix = ''): void { foreach ($this->pointer ?: [] as $xmlProperty) { list($namespace, $tagName) = SabreXml\Service::parseClarkNotation($xmlProperty['name']); @@ -297,8 +296,10 @@ protected function parseProperties(Component $parentComponent, $propertyNamePref /** * Parse a component. + * + * @throws InvalidDataException */ - protected function parseComponent(Component $parentComponent) + protected function parseComponent(Component $parentComponent): void { $components = $this->pointer['value'] ?: []; @@ -320,12 +321,9 @@ protected function parseComponent(Component $parentComponent) /** * Create a property. * - * @param string $name - * @param array $parameters - * @param string $type - * @param mixed $value + * @throws InvalidDataException */ - protected function createProperty(Component $parentComponent, $name, $parameters, $type, $value) + protected function createProperty(Component $parentComponent, string $name, array $parameters, string $type, $value): void { $property = $this->root->createProperty( $name, @@ -340,9 +338,11 @@ protected function createProperty(Component $parentComponent, $name, $parameters /** * Sets the input data. * - * @param resource|string $input + * @param resource|string|array $input + * + * @throws SabreXml\LibXMLException */ - public function setInput($input) + public function setInput($input): void { if (is_resource($input)) { $input = stream_get_contents($input); @@ -363,12 +363,8 @@ public function setInput($input) /** * Get tag name from a Clark notation. - * - * @param string $clarkedTagName - * - * @return string */ - protected static function getTagName($clarkedTagName) + protected static function getTagName(string $clarkedTagName): string { list(, $tagName) = SabreXml\Service::parseClarkNotation($clarkedTagName); diff --git a/lib/Parser/XML/Element/KeyValue.php b/lib/Parser/XML/Element/KeyValue.php index c0bbf0d9b..207f150b2 100644 --- a/lib/Parser/XML/Element/KeyValue.php +++ b/lib/Parser/XML/Element/KeyValue.php @@ -32,12 +32,8 @@ class KeyValue extends SabreXml\Element\KeyValue * * $reader->parseInnerTree() will parse the entire sub-tree, and advance to * the next element. - * - * @param XML\Reader $reader - * - * @return mixed */ - public static function xmlDeserialize(SabreXml\Reader $reader) + public static function xmlDeserialize(SabreXml\Reader $reader): array { // If there's no children, we don't do anything. if ($reader->isEmptyElement) { diff --git a/lib/Property.php b/lib/Property.php index 56096dafe..53a252fb2 100644 --- a/lib/Property.php +++ b/lib/Property.php @@ -16,45 +16,40 @@ */ abstract class Property extends Node { + /** + * The root document. + */ + public ?Component $root; + /** * Property name. * * This will contain a string such as DTSTART, SUMMARY, FN. - * - * @var string */ - public $name; + public ?string $name; /** * Property group. * * This is only used in vcards - * - * @var string|null */ - public $group; + public ?string $group; /** * List of parameters. - * - * @var array */ - public $parameters = []; + public array $parameters = []; /** * Current value. - * - * @var mixed */ protected $value; /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ';'; + public string $delimiter = ';'; /** * Creates the generic property. @@ -62,12 +57,11 @@ abstract class Property extends Node * Parameters must be specified in key=>value syntax. * * @param Component $root The root document - * @param string $name * @param string|array|null $value * @param array $parameters List of parameters - * @param string $group The vcard property group + * @param string|null $group The vcard property group */ - public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) + public function __construct(Component $root, ?string $name, $value = null, array $parameters = [], string $group = null) { $this->name = $name; $this->group = $group; @@ -90,7 +84,7 @@ public function __construct(Component $root, $name, $value = null, array $parame * * @param string|array $value */ - public function setValue($value) + public function setValue($value): void { $this->value = $value; } @@ -103,28 +97,26 @@ public function setValue($value) * it as a string. * * To get the correct multi-value version, use getParts. - * - * @return string */ public function getValue() { if (is_array($this->value)) { if (0 == count($this->value)) { - return; + return null; } elseif (1 === count($this->value)) { return $this->value[0]; - } else { - return $this->getRawMimeDirValue(); } - } else { - return $this->value; + + return $this->getRawMimeDirValue(); } + + return $this->value; } /** * Sets a multi-valued property. */ - public function setParts(array $parts) + public function setParts(array $parts): void { $this->value = $parts; } @@ -134,10 +126,8 @@ public function setParts(array $parts) * * This method always returns an array, if there was only a single value, * it will still be wrapped in an array. - * - * @return array */ - public function getParts() + public function getParts(): array { if (is_null($this->value)) { return []; @@ -155,10 +145,9 @@ public function getParts() * combined. * If nameless parameter is added, we try to guess its name. * - * @param string $name * @param string|array|null $value */ - public function add($name, $value = null) + public function add(?string $name, $value = null): void { $noName = false; if (null === $name) { @@ -177,10 +166,8 @@ public function add($name, $value = null) /** * Returns an iterable list of children. - * - * @return array */ - public function parameters() + public function parameters(): array { return $this->parameters; } @@ -190,34 +177,26 @@ public function parameters() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - abstract public function getValueType(); + abstract public function getValueType(): string; /** * Sets a raw value coming from a mimedir (iCalendar/vCard) file. * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - abstract public function setRawMimeDirValue($val); + abstract public function setRawMimeDirValue(string $val): void; /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - abstract public function getRawMimeDirValue(); + abstract public function getRawMimeDirValue(): string; /** * Turns the object back into a serialized blob. - * - * @return string */ - public function serialize() + public function serialize(): string { $str = $this->name; if ($this->group) { @@ -248,10 +227,8 @@ public function serialize() * Returns the value, in the format it should be encoded for JSON. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { return $this->getParts(); } @@ -261,7 +238,7 @@ public function getJsonValue() * * The value must always be an array. */ - public function setJsonValue(array $value) + public function setJsonValue(array $value): void { if (1 === count($value)) { $this->setValue(reset($value)); @@ -273,11 +250,9 @@ public function setJsonValue(array $value) /** * This method returns an array, with the representation as it should be * encoded in JSON. This is used to create jCard or jCal documents. - * - * @return array */ #[\ReturnTypeWillChange] - public function jsonSerialize() + public function jsonSerialize(): array { $parameters = []; @@ -304,10 +279,12 @@ public function jsonSerialize() } /** - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal + * Hydrate data from an XML subtree, as it would appear in a xCard or xCal * object. + * + * @throws InvalidDataException */ - public function setXmlValue(array $value) + public function setXmlValue(array $value): void { $this->setJsonValue($value); } @@ -318,7 +295,7 @@ public function setXmlValue(array $value) * * @param Xml\Writer $writer XML writer */ - public function xmlSerialize(Xml\Writer $writer) + public function xmlSerialize(Xml\Writer $writer): void { $parameters = []; @@ -354,7 +331,7 @@ public function xmlSerialize(Xml\Writer $writer) * * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { $valueType = strtolower($this->getValueType()); @@ -370,11 +347,9 @@ protected function xmlSerializeValue(Xml\Writer $writer) * * If the property only had a single value, you will get just that. In the * case the property had multiple values, the contents will be escaped and - * combined with ,. - * - * @return string + * combined with comma. */ - public function __toString() + public function __toString(): string { return (string) $this->getValue(); } @@ -383,22 +358,18 @@ public function __toString() /** * Checks if an array element exists. - * - * @param mixed $name - * - * @return bool */ #[\ReturnTypeWillChange] - public function offsetExists($name) + public function offsetExists($offset): bool { - if (is_int($name)) { - return parent::offsetExists($name); + if (is_int($offset)) { + return parent::offsetExists($offset); } - $name = strtoupper($name); + $offset = strtoupper($offset); foreach ($this->parameters as $parameter) { - if ($parameter->name == $name) { + if ($parameter->name == $offset) { return true; } } @@ -411,36 +382,34 @@ public function offsetExists($name) * * If the parameter does not exist, null is returned. * - * @param string $name - * - * @return Node + * @param string|int $offset */ #[\ReturnTypeWillChange] - public function offsetGet($name) + public function offsetGet($offset): ?Node { - if (is_int($name)) { - return parent::offsetGet($name); + if (is_int($offset)) { + return parent::offsetGet($offset); } - $name = strtoupper($name); + $offset = strtoupper($offset); - if (!isset($this->parameters[$name])) { - return; + if (!isset($this->parameters[$offset])) { + return null; } - return $this->parameters[$name]; + return $this->parameters[$offset]; } /** * Creates a new parameter. * - * @param string $name - * @param mixed $value + * @param string|int $offset */ #[\ReturnTypeWillChange] - public function offsetSet($name, $value) + public function offsetSet($offset, $value): void { - if (is_int($name)) { - parent::offsetSet($name, $value); + if (is_int($offset)) { + parent::offsetSet($offset, $value); + // @codeCoverageIgnoreStart // This will never be reached, because an exception is always // thrown. @@ -448,20 +417,21 @@ public function offsetSet($name, $value) // @codeCoverageIgnoreEnd } - $param = new Parameter($this->root, $name, $value); + $param = new Parameter($this->root, $offset, $value); $this->parameters[$param->name] = $param; } /** * Removes one or more parameters with the specified name. * - * @param string $name + * @param string|int $offset */ #[\ReturnTypeWillChange] - public function offsetUnset($name) + public function offsetUnset($offset): void { - if (is_int($name)) { - parent::offsetUnset($name); + if (is_int($offset)) { + parent::offsetUnset($offset); + // @codeCoverageIgnoreStart // This will never be reached, because an exception is always // thrown. @@ -469,7 +439,7 @@ public function offsetUnset($name) // @codeCoverageIgnoreEnd } - unset($this->parameters[strtoupper($name)]); + unset($this->parameters[strtoupper($offset)]); } /* }}} */ @@ -499,12 +469,8 @@ public function __clone() * * level - (number between 1 and 3 with severity information) * * message - (human readable message) * * node - (reference to the offending node) - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $warnings = []; @@ -514,10 +480,8 @@ public function validate($options = 0) $level = 3; if ($options & self::REPAIR) { $newValue = StringUtil::convertToUTF8($oldValue); - if (true || StringUtil::isUTF8($newValue)) { - $this->setRawMimeDirValue($newValue); - $level = 1; - } + $this->setRawMimeDirValue($newValue); + $level = 1; } if (preg_match('%([\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', $oldValue, $matches)) { @@ -533,11 +497,11 @@ public function validate($options = 0) ]; } - // Checking if the propertyname does not contain any invalid bytes. + // Checking if the property name does not contain any invalid bytes. if (!preg_match('/^([A-Z0-9-]+)$/', $this->name)) { $warnings[] = [ 'level' => $options & self::REPAIR ? 1 : 3, - 'message' => 'The propertyname: '.$this->name.' contains invalid characters. Only A-Z, 0-9 and - are allowed', + 'message' => 'The property name: '.$this->name.' contains invalid characters. Only A-Z, 0-9 and - are allowed', 'node' => $this, ]; if ($options & self::REPAIR) { @@ -546,7 +510,7 @@ public function validate($options = 0) str_replace('_', '-', $this->name) ); // Removing every other invalid character - $this->name = preg_replace('/([^A-Z0-9-])/u', '', $this->name); + $this->name = \preg_replace('/([^A-Z0-9-])/u', '', $this->name); } } @@ -558,6 +522,7 @@ public function validate($options = 0) 'node' => $this, ]; } else { + /** @var Property $encoding */ $encoding = (string) $encoding; $allowedEncoding = []; @@ -571,7 +536,7 @@ public function validate($options = 0) break; case Document::VCARD30: $allowedEncoding = ['B']; - //Repair vCard30 that use BASE64 encoding + // Repair vCard30 that use BASE64 encoding if ($options & self::REPAIR) { if ('BASE64' === strtoupper($encoding)) { $encoding = 'B'; @@ -609,7 +574,7 @@ public function validate($options = 0) * It's intended to remove all circular references, so PHP can easily clean * it up. */ - public function destroy() + public function destroy(): void { parent::destroy(); foreach ($this->parameters as $param) { diff --git a/lib/Property/Binary.php b/lib/Property/Binary.php index 1262dd054..25cda8d25 100644 --- a/lib/Property/Binary.php +++ b/lib/Property/Binary.php @@ -23,10 +23,8 @@ class Binary extends Property /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Updates the current value. @@ -35,7 +33,7 @@ class Binary extends Property * * @param string|array $value */ - public function setValue($value) + public function setValue($value): void { if (is_array($value)) { if (1 === count($value)) { @@ -53,20 +51,16 @@ public function setValue($value) * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->value = base64_decode($val); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return base64_encode($this->value); } @@ -76,10 +70,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'BINARY'; } @@ -88,10 +80,8 @@ public function getValueType() * Returns the value, in the format it should be encoded for json. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { return [base64_encode($this->getValue())]; } @@ -101,7 +91,7 @@ public function getJsonValue() * * The value must always be an array. */ - public function setJsonValue(array $value) + public function setJsonValue(array $value): void { $value = array_map('base64_decode', $value); parent::setJsonValue($value); diff --git a/lib/Property/Boolean.php b/lib/Property/Boolean.php index 4bd6ffdfe..cdc3408aa 100644 --- a/lib/Property/Boolean.php +++ b/lib/Property/Boolean.php @@ -23,21 +23,17 @@ class Boolean extends Property * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { - $val = 'TRUE' === strtoupper($val) ? true : false; + $val = 'TRUE' === strtoupper($val); $this->setValue($val); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return $this->value ? 'TRUE' : 'FALSE'; } @@ -47,19 +43,17 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'BOOLEAN'; } /** - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal + * Hydrate data from an XML subtree, as it would appear in a xCard or xCal * object. */ - public function setXmlValue(array $value) + public function setXmlValue(array $value): void { $value = array_map( function ($value) { diff --git a/lib/Property/FlatText.php b/lib/Property/FlatText.php index d15cfe051..eee1316e2 100644 --- a/lib/Property/FlatText.php +++ b/lib/Property/FlatText.php @@ -2,20 +2,22 @@ namespace Sabre\VObject\Property; +use Sabre\VObject\InvalidDataException; + /** * FlatText property. * * This object represents certain TEXT values. * * Specifically, this property is used for text values where there is only 1 - * part. Semi-colons and colons will be de-escaped when deserializing, but if - * any semi-colons or commas appear without a backslash, we will not assume + * part. Semicolons and colons will be de-escaped when deserializing, but if + * any semicolons or commas appear without a backslash, we will not assume * that they are delimiters. * - * vCard 2.1 specifically has a whole bunch of properties where this may + * vCard 2.1 specifically has a bunch of properties where this may * happen, as it only defines a delimiter for a few properties. * - * vCard 4.0 states something similar. An unescaped semi-colon _may_ be a + * vCard 4.0 states something similar. An unescaped semicolon _may_ be a * delimiter, depending on the property. * * @copyright Copyright (C) fruux GmbH (https://fruux.com/) @@ -26,19 +28,17 @@ class FlatText extends Text { /** * Field separator. - * - * @var string */ - public $delimiter = ','; + public string $delimiter = ','; /** * Sets the value as a quoted-printable encoded string. * - * Overriding this so we're not splitting on a ; delimiter. + * Overriding this so that we're not splitting on a semicolon delimiter. * - * @param string $val + * @throws InvalidDataException */ - public function setQuotedPrintableValue($val) + public function setQuotedPrintableValue(string $val): void { $val = quoted_printable_decode($val); $this->setValue($val); diff --git a/lib/Property/FloatValue.php b/lib/Property/FloatValue.php index e780ae6c1..7a36e0976 100644 --- a/lib/Property/FloatValue.php +++ b/lib/Property/FloatValue.php @@ -20,20 +20,16 @@ class FloatValue extends Property /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ';'; + public string $delimiter = ';'; /** * Sets a raw value coming from a mimedir (iCalendar/vCard) file. * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $val = explode($this->delimiter, $val); foreach ($val as &$item) { @@ -44,10 +40,8 @@ public function setRawMimeDirValue($val) /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return implode( $this->delimiter, @@ -60,10 +54,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'FLOAT'; } @@ -72,10 +64,8 @@ public function getValueType() * Returns the value, in the format it should be encoded for JSON. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { $val = array_map('floatval', $this->getParts()); @@ -91,10 +81,10 @@ public function getJsonValue() } /** - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal + * Hydrate data from an XML subtree, as it would appear in a xCard or xCal * object. */ - public function setXmlValue(array $value) + public function setXmlValue(array $value): void { $value = array_map('floatval', $value); parent::setXmlValue($value); @@ -103,10 +93,8 @@ public function setXmlValue(array $value) /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. - * - * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { // Special-casing the GEO property. // diff --git a/lib/Property/ICalendar/CalAddress.php b/lib/Property/ICalendar/CalAddress.php index 2dbbc6eaf..01969e87d 100644 --- a/lib/Property/ICalendar/CalAddress.php +++ b/lib/Property/ICalendar/CalAddress.php @@ -18,20 +18,16 @@ class CalAddress extends Text /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'CAL-ADDRESS'; } @@ -43,17 +39,19 @@ public function getValueType() * uris to lower-case. * * Evolution in particular tends to encode mailto: as MAILTO:. - * - * @return string */ - public function getNormalizedValue() + public function getNormalizedValue(): string { $input = $this->getValue(); if (!strpos($input, ':')) { return $input; } list($schema, $everythingElse) = explode(':', $input, 2); + $schema = strtolower($schema); + if ('mailto' === $schema) { + $everythingElse = strtolower($everythingElse); + } - return strtolower($schema).':'.$everythingElse; + return $schema.':'.$everythingElse; } } diff --git a/lib/Property/ICalendar/DateTime.php b/lib/Property/ICalendar/DateTime.php index afeb8ff81..1892991a2 100644 --- a/lib/Property/ICalendar/DateTime.php +++ b/lib/Property/ICalendar/DateTime.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Property\ICalendar; -use DateTimeInterface; -use DateTimeZone; use Sabre\VObject\DateTimeParser; use Sabre\VObject\InvalidDataException; use Sabre\VObject\Property; @@ -32,16 +30,18 @@ class DateTime extends Property * * @var string|null */ - public $delimiter = ','; + public string $delimiter = ','; /** * Sets a multi-valued property. * * You may also specify DateTime objects here. + * + * @throws InvalidDataException */ - public function setParts(array $parts) + public function setParts(array $parts): void { - if (isset($parts[0]) && $parts[0] instanceof DateTimeInterface) { + if (isset($parts[0]) && $parts[0] instanceof \DateTimeInterface) { $this->setDateTimes($parts); } else { parent::setParts($parts); @@ -55,13 +55,15 @@ public function setParts(array $parts) * * Instead of strings, you may also use DateTime here. * - * @param string|array|DateTimeInterface $value + * @param string|array|\DateTimeInterface $value + * + * @throws InvalidDataException */ - public function setValue($value) + public function setValue($value): void { - if (is_array($value) && isset($value[0]) && $value[0] instanceof DateTimeInterface) { + if (is_array($value) && isset($value[0]) && $value[0] instanceof \DateTimeInterface) { $this->setDateTimes($value); - } elseif ($value instanceof DateTimeInterface) { + } elseif ($value instanceof \DateTimeInterface) { $this->setDateTimes([$value]); } else { parent::setValue($value); @@ -74,29 +76,25 @@ public function setValue($value) * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. * - * @param string $val + * @throws InvalidDataException */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue(explode($this->delimiter, $val)); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return implode($this->delimiter, $this->getParts()); } /** * Returns true if this is a DATE-TIME value, false if it's a DATE. - * - * @return bool */ - public function hasTime() + public function hasTime(): bool { return 'DATE' !== strtoupper((string) $this['VALUE']); } @@ -106,13 +104,13 @@ public function hasTime() * * Note that DATE is always floating. */ - public function isFloating() + public function isFloating(): bool { return - !$this->hasTime() || - ( - !isset($this['TZID']) && - false === strpos($this->getValue(), 'Z') + !$this->hasTime() + || ( + !isset($this['TZID']) + && false === strpos($this->getValue(), 'Z') ); } @@ -127,15 +125,13 @@ public function isFloating() * property or floating time, we will use the DateTimeZone argument to * figure out the exact date. * - * @param DateTimeZone $timeZone - * - * @return \DateTimeImmutable + * @throws InvalidDataException */ - public function getDateTime(DateTimeZone $timeZone = null, bool $activeCustomizedGuesser = true) + public function getDateTime(\DateTimeZone $timeZone = null, bool $activeCustomizedGuesser = true): ?\DateTimeImmutable { $dt = $this->getDateTimes($timeZone, $activeCustomizedGuesser); if (!$dt) { - return; + return null; } return $dt[0]; @@ -148,14 +144,14 @@ public function getDateTime(DateTimeZone $timeZone = null, bool $activeCustomize * property or floating time, we will use the DateTimeZone argument to * figure out the exact date. * - * @param DateTimeZone $timeZone + * @return \DateInterval[]|\DateTimeImmutable[] * - * @return \DateTimeImmutable[] - * @return \DateTime[] + * @throws InvalidDataException */ - public function getDateTimes(DateTimeZone $timeZone = null, bool $activeCustomizedGuesser = true) + public function getDateTimes(\DateTimeZone $timeZone = null, bool $activeCustomizedGuesser = true): array { // Does the property have a TZID? + /** @var Property\FlatText $tzid */ $tzid = $this['TZID']; if ($tzid) { @@ -174,8 +170,10 @@ public function getDateTimes(DateTimeZone $timeZone = null, bool $activeCustomiz * Sets the property as a DateTime object. * * @param bool isFloating If set to true, timezones will be ignored + * + * @throws InvalidDataException */ - public function setDateTime(DateTimeInterface $dt, $isFloating = false) + public function setDateTime(\DateTimeInterface $dt, $isFloating = false): void { $this->setDateTimes([$dt], $isFloating); } @@ -186,10 +184,12 @@ public function setDateTime(DateTimeInterface $dt, $isFloating = false) * The first value will be used as a reference for the timezones, and all * the other values will be adjusted for that timezone * - * @param DateTimeInterface[] $dt + * @param \DateTimeInterface[] $dt * @param bool isFloating If set to true, timezones will be ignored + * + * @throws InvalidDataException */ - public function setDateTimes(array $dt, $isFloating = false) + public function setDateTimes(array $dt, $isFloating = false): void { $values = []; @@ -236,10 +236,8 @@ public function setDateTimes(array $dt, $isFloating = false) * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return $this->hasTime() ? 'DATE-TIME' : 'DATE'; } @@ -249,19 +247,19 @@ public function getValueType() * * This method must always return an array. * - * @return array + * @throws InvalidDataException */ - public function getJsonValue() + public function getJsonValue(): array { $dts = $this->getDateTimes(); $hasTime = $this->hasTime(); $isFloating = $this->isFloating(); $tz = $dts[0]->getTimeZone(); - $isUtc = $isFloating ? false : in_array($tz->getName(), ['UTC', 'GMT', 'Z']); + $isUtc = !$isFloating && in_array($tz->getName(), ['UTC', 'GMT', 'Z']); return array_map( - function (DateTimeInterface $dt) use ($hasTime, $isUtc) { + function (\DateTimeInterface $dt) use ($hasTime, $isUtc) { if ($hasTime) { return $dt->format('Y-m-d\\TH:i:s').($isUtc ? 'Z' : ''); } else { @@ -276,8 +274,10 @@ function (DateTimeInterface $dt) use ($hasTime, $isUtc) { * Sets the json value, as it would appear in a jCard or jCal object. * * The value must always be an array. + * + * @throws InvalidDataException */ - public function setJsonValue(array $value) + public function setJsonValue(array $value): void { // dates and times in jCal have one difference to dates and times in // iCalendar. In jCal date-parts are separated by dashes, and @@ -297,14 +297,15 @@ function ($item) { * We need to intercept offsetSet, because it may be used to alter the * VALUE from DATE-TIME to DATE or vice-versa. * - * @param string $name - * @param mixed $value + * @param string|int $offset + * + * @throws InvalidDataException */ #[\ReturnTypeWillChange] - public function offsetSet($name, $value) + public function offsetSet($offset, $value): void { - parent::offsetSet($name, $value); - if ('VALUE' !== strtoupper($name)) { + parent::offsetSet($offset, $value); + if ('VALUE' !== strtoupper($offset)) { return; } @@ -329,12 +330,8 @@ public function offsetSet($name, $value) * 1 - The issue was repaired (only happens if REPAIR was turned on) * 2 - An inconsequential issue * 3 - A severe issue. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $messages = parent::validate($options); $valueType = $this->getValueType(); diff --git a/lib/Property/ICalendar/Duration.php b/lib/Property/ICalendar/Duration.php index e18fe191e..e95f355f2 100644 --- a/lib/Property/ICalendar/Duration.php +++ b/lib/Property/ICalendar/Duration.php @@ -2,7 +2,9 @@ namespace Sabre\VObject\Property\ICalendar; +use DateInterval; use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Property; /** @@ -21,30 +23,24 @@ class Duration extends Property /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ','; + public string $delimiter = ','; /** * Sets a raw value coming from a mimedir (iCalendar/vCard) file. * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue(explode($this->delimiter, $val)); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return implode($this->delimiter, $this->getParts()); } @@ -54,10 +50,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'DURATION'; } @@ -67,9 +61,9 @@ public function getValueType() * * If the property has more than one value, only the first is returned. * - * @return \DateInterval + * @throws InvalidDataException */ - public function getDateInterval() + public function getDateInterval(): \DateInterval { $parts = $this->getParts(); $value = $parts[0]; diff --git a/lib/Property/ICalendar/Period.php b/lib/Property/ICalendar/Period.php index ae8a78911..7632cb4d1 100644 --- a/lib/Property/ICalendar/Period.php +++ b/lib/Property/ICalendar/Period.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Property\ICalendar; use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Property; use Sabre\Xml; @@ -22,30 +23,24 @@ class Period extends Property /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ','; + public string $delimiter = ','; /** * Sets a raw value coming from a mimedir (iCalendar/vCard) file. * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue(explode($this->delimiter, $val)); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return implode($this->delimiter, $this->getParts()); } @@ -55,10 +50,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'PERIOD'; } @@ -68,7 +61,7 @@ public function getValueType() * * The value must always be an array. */ - public function setJsonValue(array $value) + public function setJsonValue(array $value): void { $value = array_map( function ($item) { @@ -84,9 +77,9 @@ function ($item) { * * This method must always return an array. * - * @return array + * @throws InvalidDataException */ - public function getJsonValue() + public function getJsonValue(): array { $return = []; foreach ($this->getParts() as $item) { @@ -116,9 +109,9 @@ public function getJsonValue() * This method serializes only the value of a property. This is used to * create xCard or xCal documents. * - * @param Xml\Writer $writer XML writer + * @throws InvalidDataException */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { $writer->startElement(strtolower($this->getValueType())); $value = $this->getJsonValue(); diff --git a/lib/Property/ICalendar/Recur.php b/lib/Property/ICalendar/Recur.php index 3d632fec1..9a1e9e643 100644 --- a/lib/Property/ICalendar/Recur.php +++ b/lib/Property/ICalendar/Recur.php @@ -2,6 +2,8 @@ namespace Sabre\VObject\Property\ICalendar; +use Sabre\VObject\InvalidDataException; +use Sabre\VObject\Node; use Sabre\VObject\Property; use Sabre\Xml; @@ -24,6 +26,11 @@ */ class Recur extends Property { + /** + * Reference to the parent object, if this is not the top object. + */ + public ?Node $parent; + /** * Updates the current value. * @@ -31,10 +38,10 @@ class Recur extends Property * * @param string|array $value */ - public function setValue($value) + public function setValue($value): void { // If we're getting the data from json, we'll be receiving an object - if ($value instanceof \StdClass) { + if ($value instanceof \stdClass) { $value = (array) $value; } @@ -73,10 +80,8 @@ public function setValue($value) * it as a string. * * To get the correct multi-value version, use getParts. - * - * @return string */ - public function getValue() + public function getValue(): string { $out = []; foreach ($this->value as $key => $value) { @@ -89,7 +94,7 @@ public function getValue() /** * Sets a multi-valued property. */ - public function setParts(array $parts) + public function setParts(array $parts): void { $this->setValue($parts); } @@ -99,10 +104,8 @@ public function setParts(array $parts) * * This method always returns an array, if there was only a single value, * it will still be wrapped in an array. - * - * @return array */ - public function getParts() + public function getParts(): array { return $this->value; } @@ -112,20 +115,16 @@ public function getParts() * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue($val); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return $this->getValue(); } @@ -135,10 +134,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'RECUR'; } @@ -148,9 +145,9 @@ public function getValueType() * * This method must always return an array. * - * @return array + * @throws InvalidDataException */ - public function getJsonValue() + public function getJsonValue(): array { $values = []; foreach ($this->getParts() as $k => $v) { @@ -170,10 +167,8 @@ public function getJsonValue() /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. - * - * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { $valueType = strtolower($this->getValueType()); @@ -184,12 +179,8 @@ protected function xmlSerializeValue(Xml\Writer $writer) /** * Parses an RRULE value string, and turns it into a struct-ish array. - * - * @param string $value - * - * @return array */ - public static function stringToArray($value) + public static function stringToArray(string $value): array { $value = strtoupper($value); $newValue = []; @@ -227,12 +218,8 @@ public static function stringToArray($value) * 1 - The issue was repaired (only happens if REPAIR was turned on) * 2 - An inconsequential issue * 3 - A severe issue. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $repair = ($options & self::REPAIR); diff --git a/lib/Property/IntegerValue.php b/lib/Property/IntegerValue.php index 3ae775214..f1ae55d17 100644 --- a/lib/Property/IntegerValue.php +++ b/lib/Property/IntegerValue.php @@ -21,20 +21,16 @@ class IntegerValue extends Property * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue((int) $val); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return $this->value; } @@ -44,10 +40,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'INTEGER'; } @@ -56,19 +50,17 @@ public function getValueType() * Returns the value, in the format it should be encoded for json. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { return [(int) $this->getValue()]; } /** - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal + * Hydrate data from an XML subtree, as it would appear in a xCard or xCal * object. */ - public function setXmlValue(array $value) + public function setXmlValue(array $value): void { $value = array_map('intval', $value); parent::setXmlValue($value); diff --git a/lib/Property/Text.php b/lib/Property/Text.php index ac8aa066b..c606ad812 100644 --- a/lib/Property/Text.php +++ b/lib/Property/Text.php @@ -4,6 +4,7 @@ use Sabre\VObject\Component; use Sabre\VObject\Document; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Parser\MimeDir; use Sabre\VObject\Property; use Sabre\Xml; @@ -22,17 +23,13 @@ class Text extends Property /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ','; + public string $delimiter = ','; /** * List of properties that are considered 'structured'. - * - * @var array */ - protected $structuredValues = [ + protected array $structuredValues = [ // vCard 'N', 'ADR', @@ -49,10 +46,8 @@ class Text extends Property * * N must for instance be represented as 5 components, separated by ;, even * if the last few components are unused. - * - * @var array */ - protected $minimumPropertyValues = [ + protected array $minimumPropertyValues = [ 'N' => 5, 'ADR' => 7, ]; @@ -65,18 +60,17 @@ class Text extends Property * Parameter objects. * * @param Component $root The root document - * @param string $name * @param string|array|null $value * @param array $parameters List of parameters - * @param string $group The vcard property group + * @param string|null $group The vcard property group */ - public function __construct(Component $root, $name, $value = null, array $parameters = [], $group = null) + public function __construct(Component $root, string $name, $value = null, array $parameters = [], string $group = null) { // There's two types of multi-valued text properties: // 1. multivalue properties. // 2. structured value properties // - // The former is always separated by a comma, the latter by semi-colon. + // The former is always separated by a comma, the latter by semicolon. if (in_array($name, $this->structuredValues)) { $this->delimiter = ';'; } @@ -90,19 +84,17 @@ public function __construct(Component $root, $name, $value = null, array $parame * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. * - * @param string $val + * @throws InvalidDataException */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue(MimeDir::unescapeValue($val, $this->delimiter)); } /** * Sets the value as a quoted-printable encoded string. - * - * @param string $val */ - public function setQuotedPrintableValue($val) + public function setQuotedPrintableValue(string $val): void { $val = quoted_printable_decode($val); @@ -119,15 +111,13 @@ public function setQuotedPrintableValue($val) /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { $val = $this->getParts(); if (isset($this->minimumPropertyValues[$this->name])) { - $val = array_pad($val, $this->minimumPropertyValues[$this->name], ''); + $val = \array_pad($val, $this->minimumPropertyValues[$this->name], ''); } foreach ($val as &$item) { @@ -136,31 +126,31 @@ public function getRawMimeDirValue() } foreach ($item as &$subItem) { - $subItem = strtr( - $subItem, - [ - '\\' => '\\\\', - ';' => '\;', - ',' => '\,', - "\n" => '\n', - "\r" => '', - ] - ); + if (!\is_null($subItem)) { + $subItem = strtr( + $subItem, + [ + '\\' => '\\\\', + ';' => '\;', + ',' => '\,', + "\n" => '\n', + "\r" => '', + ] + ); + } } - $item = implode(',', $item); + $item = \implode(',', $item); } - return implode($this->delimiter, $val); + return \implode($this->delimiter, $val); } /** * Returns the value, in the format it should be encoded for json. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { // Structured text values should always be returned as a single // array-item. Multi-value text should be returned as multiple items in @@ -177,20 +167,16 @@ public function getJsonValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'TEXT'; } /** * Turns the object back into a serialized blob. - * - * @return string */ - public function serialize() + public function serialize(): string { // We need to kick in a special type of encoding, if it's a 2.1 vcard. if (Document::VCARD21 !== $this->root->getDocumentType()) { @@ -230,7 +216,7 @@ public function serialize() if (false !== \strpos($val, "\n")) { $str .= ';ENCODING=QUOTED-PRINTABLE:'; $lastLine = $str; - $out = null; + $out = ''; // The PHP built-in quoted-printable-encode does not correctly // encode newlines for us. Specifically, the \r\n sequence must in @@ -276,14 +262,12 @@ public function serialize() /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. - * - * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { $values = $this->getParts(); - $map = function ($items) use ($values, $writer) { + $map = function (array $items) use ($values, $writer): void { foreach ($items as $i => $item) { $writer->writeElement( $item, @@ -360,26 +344,22 @@ protected function xmlSerializeValue(Xml\Writer $writer) * * level - (number between 1 and 3 with severity information) * * message - (human readable message) * * node - (reference to the offending node) - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $warnings = parent::validate($options); if (isset($this->minimumPropertyValues[$this->name])) { $minimum = $this->minimumPropertyValues[$this->name]; $parts = $this->getParts(); - if (count($parts) < $minimum) { + if (\count($parts) < $minimum) { $warnings[] = [ 'level' => $options & self::REPAIR ? 1 : 3, - 'message' => 'The '.$this->name.' property must have at least '.$minimum.' values. It only has '.count($parts), + 'message' => 'The '.$this->name.' property must have at least '.$minimum.' values. It only has '.\count($parts), 'node' => $this, ]; if ($options & self::REPAIR) { - $parts = array_pad($parts, $minimum, ''); + $parts = \array_pad($parts, $minimum, ''); $this->setParts($parts); } } diff --git a/lib/Property/Time.php b/lib/Property/Time.php index 1b81609aa..ed314fc0d 100644 --- a/lib/Property/Time.php +++ b/lib/Property/Time.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Property; use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; /** * Time property. @@ -18,20 +19,16 @@ class Time extends Text /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'TIME'; } @@ -41,7 +38,7 @@ public function getValueType() * * The value must always be an array. */ - public function setJsonValue(array $value) + public function setJsonValue(array $value): void { // Removing colons from value. $value = str_replace( @@ -62,9 +59,9 @@ public function setJsonValue(array $value) * * This method must always return an array. * - * @return array + * @throws InvalidDataException */ - public function getJsonValue() + public function getJsonValue(): array { $parts = DateTimeParser::parseVCardTime($this->getValue()); $timeStr = ''; @@ -115,10 +112,10 @@ public function getJsonValue() } /** - * Hydrate data from a XML subtree, as it would appear in a xCard or xCal + * Hydrate data from an XML subtree, as it would appear in a xCard or xCal * object. */ - public function setXmlValue(array $value) + public function setXmlValue(array $value): void { $value = array_map( function ($value) { diff --git a/lib/Property/Unknown.php b/lib/Property/Unknown.php index 6f404c286..3bcf61351 100644 --- a/lib/Property/Unknown.php +++ b/lib/Property/Unknown.php @@ -18,10 +18,8 @@ class Unknown extends Text * Returns the value, in the format it should be encoded for json. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { return [$this->getRawMimeDirValue()]; } @@ -31,10 +29,8 @@ public function getJsonValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'UNKNOWN'; } diff --git a/lib/Property/Uri.php b/lib/Property/Uri.php index 1ad1fb199..228b7090f 100644 --- a/lib/Property/Uri.php +++ b/lib/Property/Uri.php @@ -3,7 +3,6 @@ namespace Sabre\VObject\Property; use Sabre\VObject\Parameter; -use Sabre\VObject\Property; /** * URI property. @@ -19,30 +18,24 @@ class Uri extends Text /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'URI'; } /** * Returns an iterable list of children. - * - * @return array */ - public function parameters() + public function parameters(): array { $parameters = parent::parameters(); if (!isset($parameters['VALUE']) && in_array($this->name, ['URL', 'PHOTO'])) { @@ -65,13 +58,11 @@ public function parameters() * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { // Normally we don't need to do any type of unescaping for these - // properties, however.. we've noticed that Google Contacts + // properties, however, we've noticed that Google Contacts // specifically escapes the colon (:) with a backslash. While I have // no clue why they thought that was a good idea, I'm unescaping it // anyway. @@ -100,10 +91,8 @@ public function setRawMimeDirValue($val) /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { if (is_array($this->value)) { $value = $this->value[0]; diff --git a/lib/Property/UtcOffset.php b/lib/Property/UtcOffset.php index 04b88447f..09aab0151 100644 --- a/lib/Property/UtcOffset.php +++ b/lib/Property/UtcOffset.php @@ -2,6 +2,8 @@ namespace Sabre\VObject\Property; +use Sabre\VObject\InvalidDataException; + /** * UtcOffset property. * @@ -16,20 +18,16 @@ class UtcOffset extends Text /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'UTC-OFFSET'; } @@ -38,8 +36,10 @@ public function getValueType() * Sets the JSON value, as it would appear in a jCard or jCal object. * * The value must always be an array. + * + * @throws InvalidDataException */ - public function setJsonValue(array $value) + public function setJsonValue(array $value): void { $value = array_map( function ($value) { @@ -54,10 +54,8 @@ function ($value) { * Returns the value, in the format it should be encoded for JSON. * * This method must always return an array. - * - * @return array */ - public function getJsonValue() + public function getJsonValue(): array { return array_map( function ($value) { diff --git a/lib/Property/VCard/Date.php b/lib/Property/VCard/Date.php index fc679d572..1ad9fedc2 100644 --- a/lib/Property/VCard/Date.php +++ b/lib/Property/VCard/Date.php @@ -18,10 +18,8 @@ class Date extends DateAndOrTime * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'DATE'; } @@ -29,7 +27,7 @@ public function getValueType() /** * Sets the property as a DateTime object. */ - public function setDateTime(\DateTimeInterface $dt) + public function setDateTime(\DateTimeInterface $dt): void { $this->value = $dt->format('Ymd'); } diff --git a/lib/Property/VCard/DateAndOrTime.php b/lib/Property/VCard/DateAndOrTime.php index 7bf79c48c..e87bf1b3a 100644 --- a/lib/Property/VCard/DateAndOrTime.php +++ b/lib/Property/VCard/DateAndOrTime.php @@ -3,7 +3,6 @@ namespace Sabre\VObject\Property\VCard; use DateTime; -use DateTimeImmutable; use DateTimeInterface; use Sabre\VObject\DateTimeParser; use Sabre\VObject\InvalidDataException; @@ -23,20 +22,16 @@ class DateAndOrTime extends Property { /** * Field separator. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'DATE-AND-OR-TIME'; } @@ -46,12 +41,12 @@ public function getValueType() * * You may also specify DateTimeInterface objects here. */ - public function setParts(array $parts) + public function setParts(array $parts): void { if (count($parts) > 1) { throw new \InvalidArgumentException('Only one value allowed'); } - if (isset($parts[0]) && $parts[0] instanceof DateTimeInterface) { + if (isset($parts[0]) && $parts[0] instanceof \DateTimeInterface) { $this->setDateTime($parts[0]); } else { parent::setParts($parts); @@ -65,11 +60,11 @@ public function setParts(array $parts) * * Instead of strings, you may also use DateTimeInterface here. * - * @param string|array|DateTimeInterface $value + * @param string|array|\DateTimeInterface $value */ - public function setValue($value) + public function setValue($value): void { - if ($value instanceof DateTimeInterface) { + if ($value instanceof \DateTimeInterface) { $this->setDateTime($value); } else { parent::setValue($value); @@ -79,7 +74,7 @@ public function setValue($value) /** * Sets the property as a DateTime object. */ - public function setDateTime(DateTimeInterface $dt) + public function setDateTime(\DateTimeInterface $dt): void { $tz = $dt->getTimeZone(); $isUtc = in_array($tz->getName(), ['UTC', 'GMT', 'Z']); @@ -108,11 +103,11 @@ public function setDateTime(DateTimeInterface $dt) * current values for those. So at the time of writing, if the year was * omitted, we would have filled in 2014. * - * @return DateTimeImmutable + * @throws InvalidDataException */ - public function getDateTime() + public function getDateTime(): \DateTimeImmutable { - $now = new DateTime(); + $now = new \DateTime(); $tzFormat = 0 === $now->getTimezone()->getOffset($now) ? '\\Z' : 'O'; $nowParts = DateTimeParser::parseVCardDateTime($now->format('Ymd\\This'.$tzFormat)); @@ -128,7 +123,7 @@ public function getDateTime() } } - return new DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]"); + return new \DateTimeImmutable("$dateParts[year]-$dateParts[month]-$dateParts[date] $dateParts[hour]:$dateParts[minute]:$dateParts[second] $dateParts[timezone]"); } /** @@ -136,9 +131,9 @@ public function getDateTime() * * This method must always return an array. * - * @return array + * @throws InvalidDataException */ - public function getJsonValue() + public function getJsonValue(): array { $parts = DateTimeParser::parseVCardDateTime($this->getValue()); @@ -228,16 +223,16 @@ public function getJsonValue() * This method serializes only the value of a property. This is used to * create xCard or xCal documents. * - * @param Xml\Writer $writer XML writer + * @throws InvalidDataException */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { $valueType = strtolower($this->getValueType()); $parts = DateTimeParser::parseVCardDateAndOrTime($this->getValue()); $value = ''; // $d = defined - $d = function ($part) use ($parts) { + $d = function ($part) use ($parts): bool { return !is_null($parts[$part]); }; @@ -264,7 +259,7 @@ protected function xmlSerializeValue(Xml\Writer $writer) $value .= '---'.$r('date'); } - // # 4.3.2 + // # 4.3.2 // value-time = element time { // xsd:string { pattern = "(\d\d(\d\d(\d\d)?)?|-\d\d(\d\d?)|--\d\d)" // ~ "(Z|[+\-]\d\d(\d\d)?)?" } @@ -307,20 +302,16 @@ protected function xmlSerializeValue(Xml\Writer $writer) * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue($val); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return implode($this->delimiter, $this->getParts()); } @@ -342,12 +333,8 @@ public function getRawMimeDirValue() * 1 - The issue was repaired (only happens if REPAIR was turned on) * 2 - An inconsequential issue * 3 - A severe issue. - * - * @param int $options - * - * @return array */ - public function validate($options = 0) + public function validate(int $options = 0): array { $messages = parent::validate($options); $value = $this->getValue(); diff --git a/lib/Property/VCard/DateTime.php b/lib/Property/VCard/DateTime.php index 49c1f3555..c71071f1a 100644 --- a/lib/Property/VCard/DateTime.php +++ b/lib/Property/VCard/DateTime.php @@ -18,10 +18,8 @@ class DateTime extends DateAndOrTime * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'DATE-TIME'; } diff --git a/lib/Property/VCard/LanguageTag.php b/lib/Property/VCard/LanguageTag.php index 318ea0231..c3b996f52 100644 --- a/lib/Property/VCard/LanguageTag.php +++ b/lib/Property/VCard/LanguageTag.php @@ -20,20 +20,16 @@ class LanguageTag extends Property * * This has been 'unfolded', so only 1 line will be passed. Unescaping is * not yet done, but parameters are not included. - * - * @param string $val */ - public function setRawMimeDirValue($val) + public function setRawMimeDirValue(string $val): void { $this->setValue($val); } /** * Returns a raw mime-dir representation of the value. - * - * @return string */ - public function getRawMimeDirValue() + public function getRawMimeDirValue(): string { return $this->getValue(); } @@ -43,10 +39,8 @@ public function getRawMimeDirValue() * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'LANGUAGE-TAG'; } diff --git a/lib/Property/VCard/PhoneNumber.php b/lib/Property/VCard/PhoneNumber.php index b714ffd03..f007be3df 100644 --- a/lib/Property/VCard/PhoneNumber.php +++ b/lib/Property/VCard/PhoneNumber.php @@ -13,17 +13,15 @@ */ class PhoneNumber extends Property\Text { - protected $structuredValues = []; + protected array $structuredValues = []; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'PHONE-NUMBER'; } diff --git a/lib/Property/VCard/TimeStamp.php b/lib/Property/VCard/TimeStamp.php index da6ea3d44..80739237e 100644 --- a/lib/Property/VCard/TimeStamp.php +++ b/lib/Property/VCard/TimeStamp.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Property\VCard; use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Property\Text; use Sabre\Xml; @@ -20,20 +21,16 @@ class TimeStamp extends Text /** * In case this is a multi-value property. This string will be used as a * delimiter. - * - * @var string */ - public $delimiter = ''; + public string $delimiter = ''; /** * Returns the type of value. * * This corresponds to the VALUE= parameter. Every property also has a * 'default' valueType. - * - * @return string */ - public function getValueType() + public function getValueType(): string { return 'TIMESTAMP'; } @@ -43,9 +40,9 @@ public function getValueType() * * This method must always return an array. * - * @return array + * @throws InvalidDataException */ - public function getJsonValue() + public function getJsonValue(): array { $parts = DateTimeParser::parseVCardDateTime($this->getValue()); @@ -68,10 +65,8 @@ public function getJsonValue() /** * This method serializes only the value of a property. This is used to * create xCard or xCal documents. - * - * @param Xml\Writer $writer XML writer */ - protected function xmlSerializeValue(Xml\Writer $writer) + protected function xmlSerializeValue(Xml\Writer $writer): void { // xCard is the only XML and JSON format that has the same date and time // format than vCard. diff --git a/lib/Reader.php b/lib/Reader.php index a68c1af47..fc9c58054 100644 --- a/lib/Reader.php +++ b/lib/Reader.php @@ -2,6 +2,8 @@ namespace Sabre\VObject; +use Sabre\Xml\LibXMLException; + /** * iCalendar/vCard/jCal/jCard/xCal/xCard reader object. * @@ -18,18 +20,18 @@ class Reader * If this option is passed to the reader, it will be less strict about the * validity of the lines. */ - const OPTION_FORGIVING = 1; + public const OPTION_FORGIVING = 1; /** * If this option is turned on, any lines we cannot parse will be ignored * by the reader. */ - const OPTION_IGNORE_INVALID_LINES = 2; + public const OPTION_IGNORE_INVALID_LINES = 2; /** * If this option is turned on, it will fix unfolding parse error by adding empty space. */ - const OPTION_FIX_UNFOLDING = 4; + public const OPTION_FIX_UNFOLDING = 4; /** * Parses a vCard or iCalendar object, and returns the top component. @@ -40,18 +42,15 @@ class Reader * You can either supply a string, or a readable stream for input. * * @param string|resource $data - * @param int $options - * @param string $charset * - * @return Document + * @throws ParseException */ - public static function read($data, $options = 0, $charset = 'UTF-8') + public static function read($data, int $options = 0, string $charset = 'UTF-8'): ?Document { $parser = new Parser\MimeDir(); $parser->setCharset($charset); - $result = $parser->parse($data, $options); - return $result; + return $parser->parse($data, $options); } /** @@ -65,16 +64,15 @@ public static function read($data, $options = 0, $charset = 'UTF-8') * input. * * @param string|resource|array $data - * @param int $options * - * @return Document + * @throws EofException + * @throws ParseException|InvalidDataException */ - public static function readJson($data, $options = 0) + public static function readJson($data, int $options = 0): ?Document { $parser = new Parser\Json(); - $result = $parser->parse($data, $options); - return $result; + return $parser->parse($data, $options); } /** @@ -86,15 +84,16 @@ public static function readJson($data, $options = 0) * You can either supply a string, or a readable stream for input. * * @param string|resource $data - * @param int $options * - * @return Document + * @throws EofException + * @throws InvalidDataException + * @throws ParseException + * @throws LibXMLException */ - public static function readXML($data, $options = 0) + public static function readXML($data, int $options = 0): ?Document { $parser = new Parser\XML(); - $result = $parser->parse($data, $options); - return $result; + return $parser->parse($data, $options); } } diff --git a/lib/Recur/EventIterator.php b/lib/Recur/EventIterator.php index 61f05d7de..d79cf3132 100644 --- a/lib/Recur/EventIterator.php +++ b/lib/Recur/EventIterator.php @@ -2,12 +2,9 @@ namespace Sabre\VObject\Recur; -use DateTimeImmutable; -use DateTimeInterface; -use DateTimeZone; -use InvalidArgumentException; use Sabre\VObject\Component; use Sabre\VObject\Component\VEvent; +use Sabre\VObject\InvalidDataException; use Sabre\VObject\Settings; /** @@ -62,17 +59,13 @@ class EventIterator implements \Iterator { /** * Reference timeZone for floating dates and times. - * - * @var DateTimeZone */ - protected $timeZone; + protected \DateTimeZone $timeZone; /** * True if we're iterating an all-day event. - * - * @var bool */ - protected $allDay = false; + protected bool $allDay = false; /** * Creates the iterator. @@ -88,15 +81,18 @@ class EventIterator implements \Iterator * * The $uid parameter is only required for the first method. * - * @param Component|array $input - * @param string|null $uid - * @param DateTimeZone $timeZone reference timezone for floating dates and - * times + * @param Component|Component\VCalendar|array $input + * @param \DateTimeZone|null $timeZone reference timezone for floating dates and + * times + * + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws InvalidDataException */ - public function __construct($input, $uid = null, DateTimeZone $timeZone = null) + public function __construct($input, string $uid = null, \DateTimeZone $timeZone = null) { if (is_null($timeZone)) { - $timeZone = new DateTimeZone('UTC'); + $timeZone = new \DateTimeZone('UTC'); } $this->timeZone = $timeZone; @@ -107,16 +103,16 @@ public function __construct($input, $uid = null, DateTimeZone $timeZone = null) $events = [$input]; } else { // Calendar + UID mode. - $uid = (string) $uid; if (!$uid) { - throw new InvalidArgumentException('The UID argument is required when a VCALENDAR is passed to this constructor'); + throw new \InvalidArgumentException('The UID argument is required when a VCALENDAR is passed to this constructor'); } if (!isset($input->VEVENT)) { - throw new InvalidArgumentException('No events found in this calendar'); + throw new \InvalidArgumentException('No events found in this calendar'); } $events = $input->getByUID($uid); } + /** @var VEvent[] $events */ foreach ($events as $vevent) { if (!isset($vevent->{'RECURRENCE-ID'})) { $this->masterEvent = $vevent; @@ -136,7 +132,7 @@ public function __construct($input, $uid = null, DateTimeZone $timeZone = null) // event and use that instead. This may not always give the // desired result. if (!count($this->overriddenEvents)) { - throw new InvalidArgumentException('This VCALENDAR did not have an event with UID: '.$uid); + throw new \InvalidArgumentException('This VCALENDAR did not have an event with UID: '.$uid); } $this->masterEvent = array_shift($this->overriddenEvents); } @@ -195,40 +191,40 @@ public function __construct($input, $uid = null, DateTimeZone $timeZone = null) /** * Returns the date for the current position of the iterator. - * - * @return DateTimeImmutable */ #[\ReturnTypeWillChange] - public function current() + public function current(): ?\DateTimeImmutable { if ($this->currentDate) { return clone $this->currentDate; } + + return null; } /** * This method returns the start date for the current iteration of the * event. - * - * @return DateTimeImmutable */ - public function getDtStart() + public function getDtStart(): ?\DateTimeImmutable { if ($this->currentDate) { return clone $this->currentDate; } + + return null; } /** * This method returns the end date for the current iteration of the * event. * - * @return DateTimeImmutable + * @throws MaxInstancesExceededException|InvalidDataException */ - public function getDtEnd() + public function getDtEnd(): ?\DateTimeImmutable { if (!$this->valid()) { - return; + return null; } if ($this->currentOverriddenEvent && $this->currentOverriddenEvent->DTEND) { return $this->currentOverriddenEvent->DTEND->getDateTime($this->timeZone); @@ -245,14 +241,16 @@ public function getDtEnd() * This VEVENT will have a recurrence id, and its DTSTART and DTEND * altered. * - * @return VEvent + * @throws MaxInstancesExceededException + * @throws InvalidDataException */ - public function getEventObject() + public function getEventObject(): VEvent { if ($this->currentOverriddenEvent) { return $this->currentOverriddenEvent; } + /** @var VEvent $event */ $event = clone $this->masterEvent; // Ignoring the following block, because PHPUnit's code coverage @@ -283,11 +281,9 @@ public function getEventObject() * Returns the current position of the iterator. * * This is for us simply a 0-based index. - * - * @return int */ #[\ReturnTypeWillChange] - public function key() + public function key(): int { // The counter is always 1 ahead. return $this->counter - 1; @@ -297,10 +293,10 @@ public function key() * This is called after next, to see if the iterator is still at a valid * position, or if it's at the end. * - * @return bool + * @throws MaxInstancesExceededException */ #[\ReturnTypeWillChange] - public function valid() + public function valid(): bool { if ($this->counter > Settings::$maxRecurrences && -1 !== Settings::$maxRecurrences) { throw new MaxInstancesExceededException('Recurring events are only allowed to generate '.Settings::$maxRecurrences); @@ -312,15 +308,16 @@ public function valid() /** * Sets the iterator back to the starting point. * - * @return void + * @throws InvalidDataException */ #[\ReturnTypeWillChange] - public function rewind() + public function rewind(): void { $this->recurIterator->rewind(); // re-creating overridden event index. $index = []; foreach ($this->overriddenEvents as $key => $event) { + /** @var VEvent $event */ $stamp = $event->DTSTART->getDateTime($this->timeZone)->getTimeStamp(); $index[$stamp][] = $key; } @@ -338,10 +335,10 @@ public function rewind() /** * Advances the iterator with one step. * - * @return void + * @throws InvalidDataException */ #[\ReturnTypeWillChange] - public function next() + public function next(): void { $this->currentOverriddenEvent = null; ++$this->counter; @@ -393,8 +390,10 @@ public function next() /** * Quickly jump to a date in the future. + * + * @throws MaxInstancesExceededException|InvalidDataException */ - public function fastForward(DateTimeInterface $dateTime) + public function fastForward(\DateTimeInterface $dateTime): void { while ($this->valid() && $this->getDtEnd() <= $dateTime) { $this->next(); @@ -403,10 +402,8 @@ public function fastForward(DateTimeInterface $dateTime) /** * Returns true if this recurring event never ends. - * - * @return bool */ - public function isInfinite() + public function isInfinite(): bool { return $this->recurIterator->isInfinite(); } @@ -414,9 +411,9 @@ public function isInfinite() /** * RRULE parser. * - * @var RRuleIterator + * @var RRuleIterator|RDateIterator */ - protected $recurIterator; + protected \Iterator $recurIterator; /** * The duration, in seconds, of the master event. @@ -427,71 +424,53 @@ public function isInfinite() /** * A reference to the main (master) event. - * - * @var VEVENT */ - protected $masterEvent; + protected ?VEvent $masterEvent = null; /** * List of overridden events. - * - * @var array */ - protected $overriddenEvents = []; + protected array $overriddenEvents = []; /** * Overridden event index. * * Key is timestamp, value is the list of indexes of the item in the $overriddenEvent * property. - * - * @var array */ - protected $overriddenEventsIndex; + protected array $overriddenEventsIndex; /** * A list of recurrence-id's that are either part of EXDATE, or are * overridden. - * - * @var array */ - protected $exceptions = []; + protected array $exceptions = []; /** * Internal event counter. - * - * @var int */ - protected $counter; + protected int $counter = 0; /** * The very start of the iteration process. - * - * @var DateTimeImmutable */ - protected $startDate; + protected ?\DateTimeImmutable $startDate; /** * Where we are currently in the iteration process. - * - * @var DateTimeImmutable */ - protected $currentDate; + protected ?\DateTimeImmutable $currentDate = null; /** * The next date from the rrule parser. * * Sometimes we need to temporary store the next date, because an * overridden event came before. - * - * @var DateTimeImmutable */ - protected $nextDate; + protected ?\DateTimeImmutable $nextDate = null; /** * The event that overwrites the current iteration. - * - * @var VEVENT */ - protected $currentOverriddenEvent; + protected ?VEvent $currentOverriddenEvent = null; } diff --git a/lib/Recur/MaxInstancesExceededException.php b/lib/Recur/MaxInstancesExceededException.php index cb0835813..38d62b46b 100644 --- a/lib/Recur/MaxInstancesExceededException.php +++ b/lib/Recur/MaxInstancesExceededException.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur; -use Exception; - /** * This exception will get thrown when a recurrence rule generated more than * the maximum number of instances. @@ -12,6 +10,6 @@ * @author Evert Pot (http://evertpot.com/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ -class MaxInstancesExceededException extends Exception +class MaxInstancesExceededException extends \Exception { } diff --git a/lib/Recur/NoInstancesException.php b/lib/Recur/NoInstancesException.php index 348c02306..4c2d44aa6 100644 --- a/lib/Recur/NoInstancesException.php +++ b/lib/Recur/NoInstancesException.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur; -use Exception; - /** * This exception gets thrown when a recurrence iterator produces 0 instances. * @@ -13,6 +11,6 @@ * @author Evert Pot (http://evertpot.com/) * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License */ -class NoInstancesException extends Exception +class NoInstancesException extends \Exception { } diff --git a/lib/Recur/RDateIterator.php b/lib/Recur/RDateIterator.php index 5d56657fa..4ad688f9d 100644 --- a/lib/Recur/RDateIterator.php +++ b/lib/Recur/RDateIterator.php @@ -2,9 +2,9 @@ namespace Sabre\VObject\Recur; -use DateTimeInterface; use Iterator; use Sabre\VObject\DateTimeParser; +use Sabre\VObject\InvalidDataException; /** * RRuleParser. @@ -19,14 +19,14 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class RDateIterator implements Iterator +class RDateIterator implements \Iterator { /** * Creates the Iterator. * * @param string|array $rrule */ - public function __construct($rrule, DateTimeInterface $start) + public function __construct($rrule, \DateTimeInterface $start) { $this->startDate = $start; $this->parseRDate($rrule); @@ -36,10 +36,10 @@ public function __construct($rrule, DateTimeInterface $start) /* Implementation of the Iterator interface {{{ */ #[\ReturnTypeWillChange] - public function current() + public function current(): ?\DateTimeInterface { if (!$this->valid()) { - return; + return null; } return clone $this->currentDate; @@ -47,11 +47,9 @@ public function current() /** * Returns the current item number. - * - * @return int */ #[\ReturnTypeWillChange] - public function key() + public function key(): int { return $this->counter; } @@ -59,22 +57,18 @@ public function key() /** * Returns whether the current item is a valid item for the recurrence * iterator. - * - * @return bool */ #[\ReturnTypeWillChange] - public function valid() + public function valid(): bool { return $this->counter <= count($this->dates); } /** * Resets the iterator. - * - * @return void */ #[\ReturnTypeWillChange] - public function rewind() + public function rewind(): void { $this->currentDate = clone $this->startDate; $this->counter = 0; @@ -83,10 +77,10 @@ public function rewind() /** * Goes on to the next iteration. * - * @return void + * @throws InvalidDataException */ #[\ReturnTypeWillChange] - public function next() + public function next(): void { ++$this->counter; if (!$this->valid()) { @@ -104,10 +98,8 @@ public function next() /** * Returns true if this recurring event never ends. - * - * @return bool */ - public function isInfinite() + public function isInfinite(): bool { return false; } @@ -115,8 +107,10 @@ public function isInfinite() /** * This method allows you to quickly go to the next occurrence after the * specified date. + * + * @throws InvalidDataException */ - public function fastForward(DateTimeInterface $dt) + public function fastForward(\DateTimeInterface $dt): void { while ($this->valid() && $this->currentDate < $dt) { $this->next(); @@ -127,27 +121,21 @@ public function fastForward(DateTimeInterface $dt) * The reference start date/time for the rrule. * * All calculations are based on this initial date. - * - * @var DateTimeInterface */ - protected $startDate; + protected \DateTimeInterface $startDate; /** * The date of the current iteration. You can get this by calling * ->current(). - * - * @var DateTimeInterface */ - protected $currentDate; + protected \DateTimeInterface $currentDate; /** * The current item in the list. * * You can get this number with the key() method. - * - * @var int */ - protected $counter = 0; + protected int $counter = 0; /* }}} */ @@ -155,9 +143,9 @@ public function fastForward(DateTimeInterface $dt) * This method receives a string from an RRULE property, and populates this * class with all the values. * - * @param string|array $rrule + * @param string|array $rdate */ - protected function parseRDate($rdate) + protected function parseRDate($rdate): void { if (is_string($rdate)) { $rdate = explode(',', $rdate); @@ -168,8 +156,6 @@ protected function parseRDate($rdate) /** * Array with the RRULE dates. - * - * @var array */ - protected $dates = []; + protected array $dates = []; } diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index d09838398..0b3140bb0 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur; -use DateTimeInterface; -use Iterator; use Sabre\VObject\DateTimeParser; use Sabre\VObject\InvalidDataException; use Sabre\VObject\Property; @@ -21,14 +19,23 @@ * @author Evert Pot (http://evertpot.com/) * @license http://sabre.io/license/ Modified BSD License */ -class RRuleIterator implements Iterator +class RRuleIterator implements \Iterator { + /** + * Constant denoting the upper limit on how long into the future + * we want to iterate. The value is a unix timestamp and currently + * corresponds to the datetime 9999-12-31 11:59:59 UTC. + */ + public const dateUpperLimit = 253402300799; + /** * Creates the Iterator. * * @param string|array $rrule + * + * @throws InvalidDataException */ - public function __construct($rrule, DateTimeInterface $start) + public function __construct($rrule, \DateTimeInterface $start) { $this->startDate = $start; $this->parseRRule($rrule); @@ -38,10 +45,10 @@ public function __construct($rrule, DateTimeInterface $start) /* Implementation of the Iterator interface {{{ */ #[\ReturnTypeWillChange] - public function current() + public function current(): ?\DateTimeInterface { if (!$this->valid()) { - return; + return null; } return clone $this->currentDate; @@ -49,24 +56,20 @@ public function current() /** * Returns the current item number. - * - * @return int */ #[\ReturnTypeWillChange] - public function key() + public function key(): int { - return $this->counter; + return (int) $this->counter; } /** * Returns whether the current item is a valid item for the recurrence * iterator. This will return false if we've gone beyond the UNTIL or COUNT * statements. - * - * @return bool */ #[\ReturnTypeWillChange] - public function valid() + public function valid(): bool { if (null === $this->currentDate) { return false; @@ -80,11 +83,9 @@ public function valid() /** * Resets the iterator. - * - * @return void */ #[\ReturnTypeWillChange] - public function rewind() + public function rewind(): void { $this->currentDate = clone $this->startDate; $this->counter = 0; @@ -92,12 +93,9 @@ public function rewind() /** * Goes on to the next iteration. - * - * @param int $amount - * @return void */ #[\ReturnTypeWillChange] - public function next(int $amount = 1) + public function next(int $amount = 1): void { // Otherwise, we find the next event in the normal RRULE // sequence. @@ -125,10 +123,8 @@ public function next(int $amount = 1) /** * Returns true if this recurring event never ends. - * - * @return bool */ - public function isInfinite() + public function isInfinite(): bool { return !$this->count && !$this->until; } @@ -137,7 +133,7 @@ public function isInfinite() * This method allows you to quickly go to the next occurrence after the * specified date. */ - public function fastForward(DateTimeInterface $dt) + public function fastForward(\DateTimeInterface $dt): void { // We don't do any jumps if we have a count limit as we have to keep track of the number of occurrences if (!isset($this->count)) { @@ -152,7 +148,7 @@ public function fastForward(DateTimeInterface $dt) /** * This method allows you to quickly go to the next occurrence before the specified date. */ - public function fastForwardBefore(DateTimeInterface $dt) + public function fastForwardBefore(\DateTimeInterface $dt): void { $hasCount = isset($this->count); @@ -176,7 +172,7 @@ public function fastForwardBefore(DateTimeInterface $dt) /** * This method allows you to quickly go to the last occurrence. */ - public function fastForwardToEnd() + public function fastForwardToEnd(): void { if ($this->isInfinite()) { throw new \LogicException('Cannot fast forward to the end an infinite event.'); @@ -199,22 +195,22 @@ public function fastForwardToEnd() $this->currentDate = $previous; } - public function getCount() + public function getCount(): ?int { return $this->count; } - public function getInterval() + public function getInterval(): int { return $this->interval; } - public function getUntil() + public function getUntil(): ?\DateTimeInterface { return $this->until; } - public function getFrequency() + public function getFrequency(): string { return $this->frequency; } @@ -254,7 +250,7 @@ private function getFrequencyCoeff() * recurrence rule. Will set the position of the iterator to the last occurrence before the requested date. If the * fast forwarding failed, the position will be reset. */ - private function jumpForward(DateTimeInterface $dt) + private function jumpForward(\DateTimeInterface $dt): void { $frequencyCoeff = $this->getFrequencyCoeff(); @@ -302,86 +298,66 @@ private function jumpForward(DateTimeInterface $dt) * The reference start date/time for the rrule. * * All calculations are based on this initial date. - * - * @var DateTimeInterface */ - protected $startDate; + protected \DateTimeInterface $startDate; /** * The date of the current iteration. You can get this by calling * ->current(). - * - * @var DateTimeInterface */ - protected $currentDate; + protected ?\DateTimeInterface $currentDate; /** * Frequency is one of: secondly, minutely, hourly, daily, weekly, monthly, * yearly. - * - * @var string */ - protected $frequency; + protected string $frequency; /** * The number of recurrences, or 'null' if infinitely recurring. - * - * @var int */ - protected $count; + protected ?int $count = null; /** * The interval. * * If for example frequency is set to daily, interval = 2 would mean every * 2 days. - * - * @var int */ - protected $interval = 1; + protected int $interval = 1; /** * The last instance of this recurrence, inclusively. - * - * @var DateTimeInterface|null */ - protected $until; + protected ?\DateTimeInterface $until = null; /** * Which seconds to recur. * * This is an array of integers (between 0 and 60) - * - * @var array */ - protected $bySecond; + protected ?array $bySecond = null; /** * Which minutes to recur. * * This is an array of integers (between 0 and 59) - * - * @var array */ - protected $byMinute; + protected ?array $byMinute = null; /** * Which hours to recur. * * This is an array of integers (between 0 and 23) - * - * @var array */ - protected $byHour; + protected ?array $byHour = null; /** * The current item in the list. * * You can get this number with the key() method. - * - * @var int */ - protected $counter = 0; + protected float $counter = 0; /** * Which weekdays to recur. @@ -392,20 +368,16 @@ private function jumpForward(DateTimeInterface $dt) * this indicates the nth occurrence of a specific day within the monthly or * yearly rrule. For instance, -2TU indicates the second-last tuesday of * the month, or year. - * - * @var array */ - protected $byDay; + protected ?array $byDay = null; /** * Which days of the month to recur. * * This is an array of days of the months (1-31). The value can also be * negative. -5 for instance means the 5th last day of the month. - * - * @var array */ - protected $byMonthDay; + protected ?array $byMonthDay = null; /** * Which days of the year to recur. @@ -413,29 +385,23 @@ private function jumpForward(DateTimeInterface $dt) * This is an array with days of the year (1 to 366). The values can also * be negative. For instance, -1 will always represent the last day of the * year. (December 31st). - * - * @var array */ - protected $byYearDay; + protected ?array $byYearDay = null; /** * Which week numbers to recur. * * This is an array of integers from 1 to 53. The values can also be * negative. -1 will always refer to the last week of the year. - * - * @var array */ - protected $byWeekNo; + protected ?array $byWeekNo = null; /** * Which months to recur. * * This is an array of integers from 1 to 12. - * - * @var array */ - protected $byMonth; + protected ?array $byMonth = null; /** * Which items in an existing st to recur. @@ -448,24 +414,20 @@ private function jumpForward(DateTimeInterface $dt) * * This would be done by setting frequency to 'monthly', byDay to * 'MO,TU,WE,TH,FR' and bySetPos to -1. - * - * @var array */ - protected $bySetPos; + protected ?array $bySetPos = null; /** * When the week starts. - * - * @var string */ - protected $weekStart = 'MO'; + protected string $weekStart = 'MO'; /* Functions that advance the iterator {{{ */ /** * Does the processing for advancing the iterator for hourly frequency. */ - protected function nextHourly($amount = 1) + protected function nextHourly($amount = 1): void { $this->currentDate = $this->currentDate->modify('+'.$amount * $this->interval.' hours'); } @@ -473,7 +435,7 @@ protected function nextHourly($amount = 1) /** * Does the processing for advancing the iterator for daily frequency. */ - protected function nextDaily($amount = 1) + protected function nextDaily($amount = 1): void { if (!$this->byHour && !$this->byDay) { $this->currentDate = $this->currentDate->modify('+'.$amount * $this->interval.' days'); @@ -518,17 +480,23 @@ protected function nextDaily($amount = 1) // Current hour of the day $currentHour = $this->currentDate->format('G'); + + if ($this->currentDate->getTimestamp() > self::dateUpperLimit) { + $this->currentDate = null; + + return; + } } while ( - ($this->byDay && !in_array($currentDay, $recurrenceDays)) || - ($this->byHour && !in_array($currentHour, $recurrenceHours)) || - ($this->byMonth && !in_array($currentMonth, $recurrenceMonths)) + ($this->byDay && !in_array($currentDay, $recurrenceDays)) + || ($this->byHour && !in_array($currentHour, $recurrenceHours)) + || ($this->byMonth && !in_array($currentMonth, $recurrenceMonths)) ); } /** * Does the processing for advancing the iterator for weekly frequency. */ - protected function nextWeekly($amount = 1) + protected function nextWeekly($amount = 1): void { if (!$this->byHour && !$this->byDay) { $this->currentDate = $this->currentDate->modify('+'.($amount * $this->interval).' weeks'); @@ -579,8 +547,10 @@ protected function nextWeekly($amount = 1) /** * Does the processing for advancing the iterator for monthly frequency. + * + * @throws \Exception */ - protected function nextMonthly($amount = 1) + protected function nextMonthly($amount = 1): void { $currentDayOfMonth = $this->currentDate->format('j'); $currentHourOfMonth = $this->currentDate->format('G'); @@ -648,9 +618,6 @@ protected function nextMonthly($amount = 1) // This goes to 0 because we need to start counting at the // beginning. $currentDayOfMonth = 0; - - // For some reason the "until" parameter was not being used here, - // that's why the workaround of the 10000 year bug was needed at all $currentHourOfMonth = 0; $currentMinuteOfMonth = 0; $currentSecondOfMonth = 0; @@ -661,14 +628,10 @@ protected function nextMonthly($amount = 1) if ($this->until && $this->currentDate->getTimestamp() >= $this->until->getTimestamp()) { return; } - // let's stop it before the "until" parameter date - if ($this->until && $this->currentDate->getTimestamp() >= $this->until->getTimestamp()) { - return; - } // To prevent running this forever (better: until we hit the max date of DateTimeImmutable) we simply // stop at 9999-12-31. Looks like the year 10000 problem is not solved in php .... - if ($this->currentDate->getTimestamp() > 253402300799) { + if ($this->currentDate->getTimestamp() > self::dateUpperLimit) { $this->currentDate = null; return; @@ -685,7 +648,7 @@ protected function nextMonthly($amount = 1) /** * Does the processing for advancing the iterator for yearly frequency. */ - protected function nextYearly($amount = 1) + protected function nextYearly($amount = 1): void { $currentYear = $this->currentDate->format('Y'); $currentMonth = $this->currentDate->format('n'); @@ -897,8 +860,10 @@ protected function nextYearly($amount = 1) * class with all the values. * * @param string|array $rrule + * + * @throws InvalidDataException */ - protected function parseRRule($rrule) + protected function parseRRule($rrule): void { if (is_string($rrule)) { $rrule = Property\ICalendar\Recur::stringToArray($rrule); @@ -1029,9 +994,9 @@ protected function parseRRule($rrule) } if ( - (isset($this->byWeekNo) && $this->frequency !== 'yearly') || - (isset($this->byYearDay) && in_array($this->frequency, ['daily', 'weekly', 'monthly'], true)) || - (isset($this->byMonthDay) && $this->frequency === 'weekly') + (isset($this->byWeekNo) && 'yearly' !== $this->frequency) + || (isset($this->byYearDay) && in_array($this->frequency, ['daily', 'weekly', 'monthly'], true)) + || (isset($this->byMonthDay) && 'weekly' === $this->frequency) ) { throw new InvalidDataException('Invalid combination of FREQ with BY rules'); } @@ -1039,10 +1004,8 @@ protected function parseRRule($rrule) /** * Mappings between the day number and english day name. - * - * @var array */ - protected $dayNames = [ + protected array $dayNames = [ 0 => 'Sunday', 1 => 'Monday', 2 => 'Tuesday', @@ -1059,9 +1022,9 @@ protected function parseRRule($rrule) * The returned list is an array of arrays with as first element the day of month (1-31); * the hour; the minute and second of the occurence * - * @return array + * @throws \Exception */ - protected function getMonthlyOccurrences() + protected function getMonthlyOccurrences(): array { $startDate = clone $this->currentDate; @@ -1110,7 +1073,7 @@ protected function getMonthlyOccurrences() } } else { // There was no counter (first, second, last wednesdays), so we - // just need to add the all to the list). + // just need to add the all to the list. $byDayResults = array_merge($byDayResults, $dayHits); } } @@ -1120,8 +1083,8 @@ protected function getMonthlyOccurrences() if ($this->byMonthDay) { foreach ($this->byMonthDay as $monthDay) { // Removing values that are out of range for this month - if ($monthDay > $startDate->format('t') || - $monthDay < 0 - $startDate->format('t')) { + if ($monthDay > $startDate->format('t') + || $monthDay < 0 - $startDate->format('t')) { continue; } if ($monthDay > 0) { @@ -1189,7 +1152,7 @@ protected function getMonthlyOccurrences() * * @return array an array of arrays with the day of the month, hours, minute and seconds of the occurence */ - protected function addDailyOccurences(array $result) + protected function addDailyOccurences(array $result): array { $output = []; $hour = (int) $this->currentDate->format('G'); @@ -1213,10 +1176,8 @@ protected function addDailyOccurences(array $result) /** * Simple mapping from iCalendar day names to day numbers. - * - * @var array */ - protected $dayMap = [ + protected array $dayMap = [ 'SU' => 0, 'MO' => 1, 'TU' => 2, @@ -1226,7 +1187,7 @@ protected function addDailyOccurences(array $result) 'SA' => 6, ]; - protected function getHours() + protected function getHours(): array { $recurrenceHours = []; foreach ($this->byHour as $byHour) { @@ -1236,7 +1197,7 @@ protected function getHours() return $recurrenceHours; } - protected function getDays() + protected function getDays(): array { $recurrenceDays = []; foreach ($this->byDay as $byDay) { @@ -1249,7 +1210,7 @@ protected function getDays() return $recurrenceDays; } - protected function getMonths() + protected function getMonths(): array { $recurrenceMonths = []; foreach ($this->byMonth as $byMonth) { diff --git a/lib/Settings.php b/lib/Settings.php index b0bb80a82..5e50f914f 100644 --- a/lib/Settings.php +++ b/lib/Settings.php @@ -25,7 +25,7 @@ class Settings * use-cases. In particular, it covers birthdates for virtually everyone * alive on earth, which is less than 5 people at the time of writing. */ - public static $minDate = '1900-01-01'; + public static string $minDate = '1900-01-01'; /** * The maximum date we accept for various calculations with dates, such as @@ -34,7 +34,7 @@ class Settings * The choice of 2100 is pretty arbitrary, but should cover most * appointments made for many years to come. */ - public static $maxDate = '2100-01-01'; + public static string $maxDate = '2100-01-01'; /** * The maximum number of recurrences that will be generated. @@ -51,5 +51,5 @@ class Settings * * Set this value to -1 to disable this control altogether. */ - public static $maxRecurrences = 3500; + public static int $maxRecurrences = 3500; } diff --git a/lib/Splitter/ICalendar.php b/lib/Splitter/ICalendar.php index d42566194..ccf0d1add 100644 --- a/lib/Splitter/ICalendar.php +++ b/lib/Splitter/ICalendar.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Splitter; use Sabre\VObject; +use Sabre\VObject\Component; use Sabre\VObject\Component\VCalendar; /** @@ -23,27 +24,25 @@ class ICalendar implements SplitterInterface { /** * Timezones. - * - * @var array */ - protected $vtimezones = []; + protected array $vtimezones = []; /** * iCalendar objects. - * - * @var array */ - protected $objects = []; + protected array $objects = []; /** * Constructor. * - * The splitter should receive an readable file stream as its input. + * The splitter should receive a readable file stream as its input. * * @param resource $input * @param int $options parser options, see the OPTIONS constants + * + * @throws VObject\ParseException */ - public function __construct($input, $options = 0) + public function __construct($input, int $options = 0) { $data = VObject\Reader::read($input, $options); @@ -52,7 +51,7 @@ public function __construct($input, $options = 0) } foreach ($data->children() as $component) { - if (!$component instanceof VObject\Component) { + if (!$component instanceof Component) { continue; } @@ -82,10 +81,8 @@ public function __construct($input, $options = 0) * hit the end of the stream. * * When the end is reached, null will be returned. - * - * @return \Sabre\VObject\Component|null */ - public function getNext() + public function getNext(): ?Component { if ($object = array_shift($this->objects)) { // create our baseobject @@ -100,7 +97,7 @@ public function getNext() return $object; } else { - return; + return null; } } } diff --git a/lib/Splitter/SplitterInterface.php b/lib/Splitter/SplitterInterface.php index c845ac5fc..c4014abf3 100644 --- a/lib/Splitter/SplitterInterface.php +++ b/lib/Splitter/SplitterInterface.php @@ -2,6 +2,8 @@ namespace Sabre\VObject\Splitter; +use Sabre\VObject\Component; + /** * VObject splitter. * @@ -20,7 +22,7 @@ interface SplitterInterface /** * Constructor. * - * The splitter should receive an readable file stream as its input. + * The splitter should receive a readable file stream as its input. * * @param resource $input */ @@ -31,8 +33,6 @@ public function __construct($input); * hit the end of the stream. * * When the end is reached, null will be returned. - * - * @return \Sabre\VObject\Component|null */ - public function getNext(); + public function getNext(): ?Component; } diff --git a/lib/Splitter/VCard.php b/lib/Splitter/VCard.php index a20f5c2c1..e63ae837d 100644 --- a/lib/Splitter/VCard.php +++ b/lib/Splitter/VCard.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Splitter; use Sabre\VObject; +use Sabre\VObject\Component; use Sabre\VObject\Parser\MimeDir; /** @@ -30,20 +31,18 @@ class VCard implements SplitterInterface /** * Persistent parser. - * - * @var MimeDir */ - protected $parser; + protected MimeDir $parser; /** * Constructor. * - * The splitter should receive an readable file stream as its input. + * The splitter should receive a readable file stream as its input. * * @param resource $input * @param int $options parser options, see the OPTIONS constants */ - public function __construct($input, $options = 0) + public function __construct($input, int $options = 0) { $this->input = $input; $this->parser = new MimeDir($input, $options); @@ -55,9 +54,9 @@ public function __construct($input, $options = 0) * * When the end is reached, null will be returned. * - * @return \Sabre\VObject\Component|null + * @throws VObject\ParseException */ - public function getNext() + public function getNext(): ?Component { try { $object = $this->parser->parse(); @@ -66,7 +65,7 @@ public function getNext() throw new VObject\ParseException('The supplied input contained non-VCARD data.'); } } catch (VObject\EofException $e) { - return; + return null; } return $object; diff --git a/lib/StringUtil.php b/lib/StringUtil.php index 2333d6ab9..8fe5f9f0a 100644 --- a/lib/StringUtil.php +++ b/lib/StringUtil.php @@ -13,12 +13,8 @@ class StringUtil { /** * Returns true or false depending on if a string is valid UTF-8. - * - * @param string $str - * - * @return bool */ - public static function isUTF8($str) + public static function isUTF8(string $str): bool { // Control characters if (preg_match('%[\x00-\x08\x0B-\x0C\x0E\x0F]%', $str)) { @@ -33,30 +29,14 @@ public static function isUTF8($str) * * Currently only ISO-5991-1 input and UTF-8 input is supported, but this * may be expanded upon if we receive other examples. - * - * @param string $str - * - * @return string */ - public static function convertToUTF8($str) + public static function convertToUTF8(string $str): string { - $encoding = mb_detect_encoding($str, ['UTF-8', 'ISO-8859-1', 'WINDOWS-1252'], true); - - switch ($encoding) { - case 'ISO-8859-1': - $newStr = utf8_encode($str); - break; - /* Unreachable code. Not sure yet how we can improve this - * situation. - case 'WINDOWS-1252' : - $newStr = iconv('cp1252', 'UTF-8', $str); - break; - */ - default: - $newStr = $str; + if (!mb_check_encoding($str, 'UTF-8') && mb_check_encoding($str, 'ISO-8859-1')) { + $str = mb_convert_encoding($str, 'UTF-8', 'ISO-8859-1'); } // Removing any control characters - return preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $newStr); + return preg_replace('%(?:[\x00-\x08\x0B-\x0C\x0E-\x1F\x7F])%', '', $str); } } diff --git a/lib/TimeZoneUtil.php b/lib/TimeZoneUtil.php index 3d9885b0d..79a5920af 100644 --- a/lib/TimeZoneUtil.php +++ b/lib/TimeZoneUtil.php @@ -2,17 +2,15 @@ namespace Sabre\VObject; -use DateTimeZone; -use InvalidArgumentException; use Sabre\VObject\TimezoneGuesser\FindFromMzVersionTimezone; use Sabre\VObject\TimezoneGuesser\FindFromOffset; use Sabre\VObject\TimezoneGuesser\FindFromOffsetName; use Sabre\VObject\TimezoneGuesser\FindFromOutlookCities; use Sabre\VObject\TimezoneGuesser\FindFromTimezoneIdentifier; use Sabre\VObject\TimezoneGuesser\FindFromTimezoneMap; +use Sabre\VObject\TimezoneGuesser\GuessFromCustomizedTimeZone; use Sabre\VObject\TimezoneGuesser\GuessFromLicEntry; use Sabre\VObject\TimezoneGuesser\GuessFromMsTzId; -use Sabre\VObject\TimezoneGuesser\GuessFromCustomizedTimeZone; use Sabre\VObject\TimezoneGuesser\LowercaseTimezoneIdentifier; use Sabre\VObject\TimezoneGuesser\TimezoneFinder; use Sabre\VObject\TimezoneGuesser\TimezoneGuesser; @@ -29,14 +27,13 @@ */ class TimeZoneUtil { - /** @var self */ - private static $instance = null; + private static ?TimeZoneUtil $instance = null; /** @var TimezoneGuesser[] */ - private $timezoneGuessers = []; + private array $timezoneGuessers = []; /** @var TimezoneFinder[] */ - private $timezoneFinders = []; + private array $timezoneFinders = []; private function __construct() { @@ -84,11 +81,11 @@ private function addFinder(string $key, TimezoneFinder $finder): void * Alternatively, if $failIfUncertain is set to true, it will throw an * exception if we cannot accurately determine the timezone. */ - private function findTimeZone(string $tzid, Component $vcalendar = null, bool $failIfUncertain = false, bool $activeCustomizedGuesser = false): DateTimeZone + private function findTimeZone(string $tzid, Component $vcalendar = null, bool $failIfUncertain = false, bool $activeCustomizedGuesser = false): \DateTimeZone { foreach ($this->timezoneFinders as $timezoneFinder) { $timezone = $timezoneFinder->find($tzid, $failIfUncertain); - if (!$timezone instanceof DateTimeZone) { + if (!$timezone instanceof \DateTimeZone) { continue; } @@ -111,7 +108,7 @@ private function findTimeZone(string $tzid, Component $vcalendar = null, bool $f if ((string) $vtimezone->TZID === $tzid) { foreach ($guessers as $timezoneGuesser) { $timezone = $timezoneGuesser->guess($vtimezone, $failIfUncertain); - if (!$timezone instanceof DateTimeZone) { + if (!$timezone instanceof \DateTimeZone) { continue; } @@ -122,11 +119,11 @@ private function findTimeZone(string $tzid, Component $vcalendar = null, bool $f } if ($failIfUncertain) { - throw new InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: '.$tzid); + throw new \InvalidArgumentException('We were unable to determine the correct PHP timezone for tzid: '.$tzid); } // If we got all the way here, we default to whatever has been set as the PHP default timezone. - return new DateTimeZone(date_default_timezone_get()); + return new \DateTimeZone(date_default_timezone_get()); } public static function addTimezoneGuesser(string $key, TimezoneGuesser $guesser): void @@ -139,13 +136,7 @@ public static function addTimezoneFinder(string $key, TimezoneFinder $finder): v self::getInstance()->addFinder($key, $finder); } - /** - * @param string $tzid - * @param false $failIfUncertain - * - * @return DateTimeZone - */ - public static function getTimeZone($tzid, Component $vcalendar = null, $failIfUncertain = false, bool $activeCustomizedGuesser = true) + public static function getTimeZone(string $tzid, Component $vcalendar = null, bool $failIfUncertain = false, bool $activeCustomizedGuesser = true): \DateTimeZone { return self::getInstance()->findTimeZone($tzid, $vcalendar, $failIfUncertain, $activeCustomizedGuesser); } @@ -154,139 +145,4 @@ public static function clean(): void { self::$instance = null; } - - // Keeping things for backwards compatibility - /** - * @var array|null - * - * @deprecated - */ - public static $map = null; - - /** - * List of microsoft exchange timezone ids. - * - * Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx - * - * @deprecated - */ - public static $microsoftExchangeMap = [ - 0 => 'UTC', - 31 => 'Africa/Casablanca', - // Insanely, id #2 is used for both Europe/Lisbon, and Europe/Sarajevo. - // I'm not even kidding.. We handle this special case in the - // getTimeZone method. - 2 => 'Europe/Lisbon', - 1 => 'Europe/London', - 4 => 'Europe/Berlin', - 6 => 'Europe/Prague', - 3 => 'Europe/Paris', - 69 => 'Africa/Luanda', // This was a best guess - 7 => 'Europe/Athens', - 5 => 'Europe/Bucharest', - 49 => 'Africa/Cairo', - 50 => 'Africa/Harare', - 59 => 'Europe/Helsinki', - 27 => 'Asia/Jerusalem', - 26 => 'Asia/Baghdad', - 74 => 'Asia/Kuwait', - 51 => 'Europe/Moscow', - 56 => 'Africa/Nairobi', - 25 => 'Asia/Tehran', - 24 => 'Asia/Muscat', // Best guess - 54 => 'Asia/Baku', - 48 => 'Asia/Kabul', - 58 => 'Asia/Yekaterinburg', - 47 => 'Asia/Karachi', - 23 => 'Asia/Calcutta', - 62 => 'Asia/Kathmandu', - 46 => 'Asia/Almaty', - 71 => 'Asia/Dhaka', - 66 => 'Asia/Colombo', - 61 => 'Asia/Rangoon', - 22 => 'Asia/Bangkok', - 64 => 'Asia/Krasnoyarsk', - 45 => 'Asia/Shanghai', - 63 => 'Asia/Irkutsk', - 21 => 'Asia/Singapore', - 73 => 'Australia/Perth', - 75 => 'Asia/Taipei', - 20 => 'Asia/Tokyo', - 72 => 'Asia/Seoul', - 70 => 'Asia/Yakutsk', - 19 => 'Australia/Adelaide', - 44 => 'Australia/Darwin', - 18 => 'Australia/Brisbane', - 76 => 'Australia/Sydney', - 43 => 'Pacific/Guam', - 42 => 'Australia/Hobart', - 68 => 'Asia/Vladivostok', - 41 => 'Asia/Magadan', - 17 => 'Pacific/Auckland', - 40 => 'Pacific/Fiji', - 67 => 'Pacific/Tongatapu', - 29 => 'Atlantic/Azores', - 53 => 'Atlantic/Cape_Verde', - 30 => 'America/Noronha', - 8 => 'America/Sao_Paulo', // Best guess - 32 => 'America/Argentina/Buenos_Aires', - 60 => 'America/Godthab', - 28 => 'America/St_Johns', - 9 => 'America/Halifax', - 33 => 'America/Caracas', - 65 => 'America/Santiago', - 35 => 'America/Bogota', - 10 => 'America/New_York', - 34 => 'America/Indiana/Indianapolis', - 55 => 'America/Guatemala', - 11 => 'America/Chicago', - 37 => 'America/Mexico_City', - 36 => 'America/Edmonton', - 38 => 'America/Phoenix', - 12 => 'America/Denver', // Best guess - 13 => 'America/Los_Angeles', // Best guess - 14 => 'America/Anchorage', - 15 => 'Pacific/Honolulu', - 16 => 'Pacific/Midway', - 39 => 'Pacific/Kwajalein', - ]; - - /** - * This method will load in all the tz mapping information, if it's not yet - * done. - * - * @deprecated - */ - public static function loadTzMaps() - { - if (!is_null(self::$map)) { - return; - } - - self::$map = array_merge( - include __DIR__.'/timezonedata/windowszones.php', - include __DIR__.'/timezonedata/lotuszones.php', - include __DIR__.'/timezonedata/exchangezones.php', - include __DIR__.'/timezonedata/php-workaround.php', - include __DIR__.'/timezonedata/extrazones.php' - ); - } - - /** - * This method returns an array of timezone identifiers, that are supported - * by DateTimeZone(), but not returned by DateTimeZone::listIdentifiers(). - * - * We're not using DateTimeZone::listIdentifiers(DateTimeZone::ALL_WITH_BC) because: - * - It's not supported by some PHP versions as well as HHVM. - * - It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions. - * (See timezonedata/php-bc.php and timezonedata php-workaround.php) - * - * @return array - * - * @deprecated - */ - public static function getIdentifiersBC() - { - return include __DIR__.'/timezonedata/php-bc.php'; - } } diff --git a/lib/TimezoneGuesser/FindFromMzVersionTimezone.php b/lib/TimezoneGuesser/FindFromMzVersionTimezone.php index b6290288f..5abdc1484 100644 --- a/lib/TimezoneGuesser/FindFromMzVersionTimezone.php +++ b/lib/TimezoneGuesser/FindFromMzVersionTimezone.php @@ -4,7 +4,6 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; use Sabre\VObject\TimeZoneUtil; /** @@ -14,21 +13,21 @@ */ class FindFromMzVersionTimezone implements TimezoneFinder { - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { if (strlen($tzid) < 1) { return null; } - $trailingChar = (int) $tzid[strlen($tzid)-1]; + $trailingChar = (int) $tzid[strlen($tzid) - 1]; if ($trailingChar <= 9 && $trailingChar >= 1) { $emptySpace = strrpos($tzid, ' '); - if ($emptySpace === false) { + if (false === $emptySpace) { return null; } $tz = TimeZoneUtil::getTimeZone(substr($tzid, 0, $emptySpace)); - if ($tz->getName() === 'UTC') { + if ('UTC' === $tz->getName()) { return null; } diff --git a/lib/TimezoneGuesser/FindFromOffset.php b/lib/TimezoneGuesser/FindFromOffset.php index 990ac9692..d50cb969c 100644 --- a/lib/TimezoneGuesser/FindFromOffset.php +++ b/lib/TimezoneGuesser/FindFromOffset.php @@ -4,14 +4,12 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; - /** * Some clients add 'X-LIC-LOCATION' with the olson name. */ class FindFromOffset implements TimezoneFinder { - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { // Maybe the author was hyper-lazy and just included an offset. We // support it, but we aren't happy about it. @@ -22,7 +20,7 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone // for versions under PHP 5.5.10, this bit can be taken out of the // source. // @codeCoverageIgnoreStart - return new DateTimeZone('Etc/GMT'.$matches[1].ltrim(substr($matches[2], 0, 2), '0')); + return new \DateTimeZone('Etc/GMT'.$matches[1].ltrim(substr($matches[2], 0, 2), '0')); // @codeCoverageIgnoreEnd } diff --git a/lib/TimezoneGuesser/FindFromOffsetName.php b/lib/TimezoneGuesser/FindFromOffsetName.php index 73a9eab34..0916f1283 100644 --- a/lib/TimezoneGuesser/FindFromOffsetName.php +++ b/lib/TimezoneGuesser/FindFromOffsetName.php @@ -4,11 +4,9 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; - class FindFromOffsetName implements TimezoneFinder { - public static $offsetTimezones = [ + public static array $offsetTimezones = [ '+01:00' => 'Africa/Lagos', '+02:00' => 'Africa/Cairo', '+03:00' => 'Europe/Moscow', @@ -35,7 +33,7 @@ class FindFromOffsetName implements TimezoneFinder '-11:00' => 'Pacific/Niue', ]; - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { // only handle number timezone if (strlen($tzid) > 6) { @@ -43,9 +41,9 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone } try { - $tzid = new DateTimeZone($tzid); + $tzid = new \DateTimeZone($tzid); - return new DateTimeZone(self::$offsetTimezones[$tzid->getName()]) ?? null; + return new \DateTimeZone(self::$offsetTimezones[$tzid->getName()]) ?? null; } catch (\Exception $e) { return null; } diff --git a/lib/TimezoneGuesser/FindFromOutlookCities.php b/lib/TimezoneGuesser/FindFromOutlookCities.php index 6ab672ecf..657767a37 100644 --- a/lib/TimezoneGuesser/FindFromOutlookCities.php +++ b/lib/TimezoneGuesser/FindFromOutlookCities.php @@ -4,17 +4,15 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; - class FindFromOutlookCities implements TimezoneFinder { /** - * Example: TZID:(UTC+01:00) Bruxelles\, København\, Madrid\, Paris + * Example: TZID:(UTC+01:00) Bruxelles\, København\, Madrid\, Paris. */ - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { $tzid = preg_replace('/TZID:\(UTC(\+|\-)\d{2}:\d{2}\)/', '', $tzid, -1, $count); - if ($count === 0) { + if (0 === $count) { return null; } @@ -25,16 +23,16 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone $cities = explode(', ', $tzid); - if (count($cities) === 1) { + if (1 === count($cities)) { return null; } - $tzIdentifiers = DateTimeZone::listIdentifiers(); + $tzIdentifiers = \DateTimeZone::listIdentifiers(); foreach ($cities as $city) { foreach ($tzIdentifiers as $tzIdentifier) { if (str_contains(strtolower($tzIdentifier), strtolower($city))) { - return new DateTimeZone($tzIdentifier); + return new \DateTimeZone($tzIdentifier); } } } diff --git a/lib/TimezoneGuesser/FindFromTimezoneIdentifier.php b/lib/TimezoneGuesser/FindFromTimezoneIdentifier.php index a2578bc2d..4c2c6a5a3 100644 --- a/lib/TimezoneGuesser/FindFromTimezoneIdentifier.php +++ b/lib/TimezoneGuesser/FindFromTimezoneIdentifier.php @@ -4,9 +4,6 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; -use Exception; - /** * Some clients add 'X-LIC-LOCATION' with the olson name. */ @@ -16,7 +13,7 @@ class FindFromTimezoneIdentifier implements TimezoneFinder 'Europe/Kyiv' => 'Europe/Kiev', ]; - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { // First we will just see if the tzid is a support timezone identifier. // @@ -49,19 +46,19 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone // https://bugs.php.net/bug.php?id=67881 // // That's why we're checking if we'll be able to successfully instantiate - // \DateTimeZone() before doing so. Otherwise we could simply instantiate + // \DateTimeZone() before doing so. Otherwise, we could simply instantiate // and catch the exception. - $tzIdentifiers = DateTimeZone::listIdentifiers(); + $tzIdentifiers = \DateTimeZone::listIdentifiers(); try { if ( - (in_array($tzid, $tzIdentifiers)) || - (preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches)) || - (in_array($tzid, $this->getIdentifiersBC())) + in_array($tzid, $tzIdentifiers) + || preg_match('/^GMT(\+|-)([0-9]{4})$/', $tzid, $matches) + || in_array($tzid, $this->getIdentifiersBC()) ) { - return new DateTimeZone($tzid); + return new \DateTimeZone($tzid); } - } catch (Exception $e) { + } catch (\Exception $e) { } return null; @@ -75,10 +72,8 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone * - It's not supported by some PHP versions as well as HHVM. * - It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions. * (See timezonedata/php-bc.php and timezonedata php-workaround.php) - * - * @return array */ - private function getIdentifiersBC() + private function getIdentifiersBC(): array { return include __DIR__.'/../timezonedata/php-bc.php'; } diff --git a/lib/TimezoneGuesser/FindFromTimezoneMap.php b/lib/TimezoneGuesser/FindFromTimezoneMap.php index 4e0a64e22..1fe680230 100644 --- a/lib/TimezoneGuesser/FindFromTimezoneMap.php +++ b/lib/TimezoneGuesser/FindFromTimezoneMap.php @@ -4,27 +4,25 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; - /** * Some clients add 'X-LIC-LOCATION' with the olson name. */ class FindFromTimezoneMap implements TimezoneFinder { - private $map = []; + private array $map = []; - private $patterns = [ + private array $patterns = [ '/^\((UTC|GMT)(\+|\-)[\d]{2}\:[\d]{2}\) (.*)/', '/^\((UTC|GMT)(\+|\-)[\d]{2}\.[\d]{2}\) (.*)/', ]; - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { - $tzid = str_replace(".", "", $tzid); + $tzid = str_replace('.', '', $tzid); // Next, we check if the tzid is somewhere in our tzid map. if ($this->hasTzInMap($tzid)) { - return new DateTimeZone($this->getTzFromMap($tzid)); + return new \DateTimeZone($this->getTzFromMap($tzid)); } // Some Microsoft products prefix the offset first, so let's strip that off @@ -36,7 +34,7 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone } $tzidAlternate = $matches[3]; if ($this->hasTzInMap($tzidAlternate)) { - return new DateTimeZone($this->getTzFromMap($tzidAlternate)); + return new \DateTimeZone($this->getTzFromMap($tzidAlternate)); } } @@ -51,10 +49,8 @@ public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone * - It's not supported by some PHP versions as well as HHVM. * - It also returns identifiers, that are invalid values for new DateTimeZone() on some PHP versions. * (See timezonedata/php-bc.php and timezonedata php-workaround.php) - * - * @return array */ - private function getTzMaps() + private function getTzMaps(): array { if ([] === $this->map) { $map = array_merge( @@ -65,7 +61,7 @@ private function getTzMaps() include __DIR__.'/../timezonedata/extrazones.php' ); $this->map = array_combine( - array_map(static fn (string $key) => str_replace(".", "", mb_strtolower($key, 'UTF-8')), array_keys($map)), + array_map(static fn (string $key) => str_replace('.', '', mb_strtolower($key, 'UTF-8')), array_keys($map)), array_values($map), ); } diff --git a/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php b/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php index 76a53fdb4..61d531cdf 100644 --- a/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php +++ b/lib/TimezoneGuesser/GuessFromCustomizedTimeZone.php @@ -4,21 +4,19 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; -use DateTimeImmutable; use Sabre\VObject\Component\VTimeZone; use Sabre\VObject\Recur\RRuleIterator; use Sabre\VObject\TimeZoneUtil; class GuessFromCustomizedTimeZone implements TimezoneGuesser { - public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?DateTimeZone + public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\DateTimeZone { - if (null === $vtimezone->TZID || $vtimezone->TZID->getValue() !== 'Customized Time Zone') { + if (null === $vtimezone->TZID || 'Customized Time Zone' !== $vtimezone->TZID->getValue()) { return null; } - $timezones = DateTimeZone::listIdentifiers(); + $timezones = \DateTimeZone::listIdentifiers(); $standard = $vtimezone->STANDARD; $daylight = $vtimezone->DAYLIGHT; if (!$standard) { @@ -34,8 +32,8 @@ public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?Dat $standardRRule = $standard->RRULE ? $standard->RRULE->getValue() : 'FREQ=DAILY'; // The guess will not be perfectly matched since we use the timezone data of the current year // It might be wrong if the timezone data changed in the past - $year = (new DateTimeImmutable('now'))->format('Y'); - $start = new DateTimeImmutable($year . '-01-01'); + $year = (new \DateTimeImmutable('now'))->format('Y'); + $start = new \DateTimeImmutable($year.'-01-01'); $standardIterator = new RRuleIterator($standardRRule, $start); $standardIterator->next(); @@ -48,7 +46,7 @@ public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?Dat $daylightIterator && $daylightIterator->next(); foreach ($timezones as $timezone) { - $tz = new DateTimeZone($timezone); + $tz = new \DateTimeZone($timezone); // check standard $timestamp = $standardIterator->current()->getTimestamp(); $transitions = $tz->getTransitions($timestamp, $timestamp + 1); @@ -88,8 +86,8 @@ private function parseOffsetToInteger(string $offset): int $time = $time * 60; - if ($offset[0] === "-") { - $time = $time *-1; + if ('-' === $offset[0]) { + $time = $time * -1; } return $time; diff --git a/lib/TimezoneGuesser/GuessFromLicEntry.php b/lib/TimezoneGuesser/GuessFromLicEntry.php index b57029919..fbd846e0f 100644 --- a/lib/TimezoneGuesser/GuessFromLicEntry.php +++ b/lib/TimezoneGuesser/GuessFromLicEntry.php @@ -4,7 +4,6 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; use Sabre\VObject\Component\VTimeZone; use Sabre\VObject\TimeZoneUtil; @@ -13,7 +12,7 @@ */ class GuessFromLicEntry implements TimezoneGuesser { - public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?DateTimeZone + public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\DateTimeZone { if (!isset($vtimezone->{'X-LIC-LOCATION'})) { return null; @@ -21,7 +20,7 @@ public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?Dat $lic = (string) $vtimezone->{'X-LIC-LOCATION'}; - if ($lic === 'Customized Time Zone') { + if ('Customized Time Zone' === $lic) { return null; } diff --git a/lib/TimezoneGuesser/GuessFromMsTzId.php b/lib/TimezoneGuesser/GuessFromMsTzId.php index b11ce1832..392333cb0 100644 --- a/lib/TimezoneGuesser/GuessFromMsTzId.php +++ b/lib/TimezoneGuesser/GuessFromMsTzId.php @@ -4,7 +4,6 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; use Sabre\VObject\Component\VTimeZone; class GuessFromMsTzId implements TimezoneGuesser @@ -14,12 +13,12 @@ class GuessFromMsTzId implements TimezoneGuesser * * Source: http://msdn.microsoft.com/en-us/library/aa563018(loband).aspx */ - public static $microsoftExchangeMap = [ + public static array $microsoftExchangeMap = [ 0 => 'UTC', 31 => 'Africa/Casablanca', // Insanely, id #2 is used for both Europe/Lisbon, and Europe/Sarajevo. - // I'm not even kidding.. We handle this special case in the + // I'm not even kidding. We handle this special case in the // getTimeZone method. 2 => 'Europe/Lisbon', 1 => 'Europe/London', @@ -96,7 +95,7 @@ class GuessFromMsTzId implements TimezoneGuesser 39 => 'Pacific/Kwajalein', ]; - public function guess(VTimeZone $vtimezone, bool $throwIfUnsure = false): ?DateTimeZone + public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\DateTimeZone { // Microsoft may add a magic number, which we also have an // answer for. @@ -107,11 +106,11 @@ public function guess(VTimeZone $vtimezone, bool $throwIfUnsure = false): ?DateT // 2 can mean both Europe/Lisbon and Europe/Sarajevo. if (2 === $cdoId && false !== strpos((string) $vtimezone->TZID, 'Sarajevo')) { - return new DateTimeZone('Europe/Sarajevo'); + return new \DateTimeZone('Europe/Sarajevo'); } if (isset(self::$microsoftExchangeMap[$cdoId])) { - return new DateTimeZone(self::$microsoftExchangeMap[$cdoId]); + return new \DateTimeZone(self::$microsoftExchangeMap[$cdoId]); } return null; diff --git a/lib/TimezoneGuesser/LowercaseTimezoneIdentifier.php b/lib/TimezoneGuesser/LowercaseTimezoneIdentifier.php index 69fba4424..a6887b941 100644 --- a/lib/TimezoneGuesser/LowercaseTimezoneIdentifier.php +++ b/lib/TimezoneGuesser/LowercaseTimezoneIdentifier.php @@ -4,15 +4,13 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; - class LowercaseTimezoneIdentifier implements TimezoneFinder { - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone { - foreach (DateTimeZone::listIdentifiers() as $timezone) { + foreach (\DateTimeZone::listIdentifiers() as $timezone) { if (strtolower($tzid) === strtolower($timezone)) { - return new DateTimeZone($timezone); + return new \DateTimeZone($timezone); } } diff --git a/lib/TimezoneGuesser/TimezoneFinder.php b/lib/TimezoneGuesser/TimezoneFinder.php index 5aa880a1c..220459527 100644 --- a/lib/TimezoneGuesser/TimezoneFinder.php +++ b/lib/TimezoneGuesser/TimezoneFinder.php @@ -2,9 +2,7 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; - interface TimezoneFinder { - public function find(string $tzid, bool $failIfUncertain = false): ?DateTimeZone; + public function find(string $tzid, ?bool $failIfUncertain = false): ?\DateTimeZone; } diff --git a/lib/TimezoneGuesser/TimezoneGuesser.php b/lib/TimezoneGuesser/TimezoneGuesser.php index 5e193bb52..f92eeb210 100644 --- a/lib/TimezoneGuesser/TimezoneGuesser.php +++ b/lib/TimezoneGuesser/TimezoneGuesser.php @@ -2,10 +2,9 @@ namespace Sabre\VObject\TimezoneGuesser; -use DateTimeZone; use Sabre\VObject\Component\VTimeZone; interface TimezoneGuesser { - public function guess(VTimeZone $vtimezone, bool $failIfUncertain = false): ?DateTimeZone; + public function guess(VTimeZone $vtimezone, ?bool $failIfUncertain = false): ?\DateTimeZone; } diff --git a/lib/UUIDUtil.php b/lib/UUIDUtil.php index 066af624c..e8208630c 100644 --- a/lib/UUIDUtil.php +++ b/lib/UUIDUtil.php @@ -21,42 +21,36 @@ class UUIDUtil * This function is based on a comment by Andrew Moore on php.net * * @see http://www.php.net/manual/en/function.uniqid.php#94959 - * - * @return string */ - public static function getUUID() + public static function getUUID(): string { return sprintf( '%04x%04x-%04x-%04x-%04x-%04x%04x%04x', // 32 bits for "time_low" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), + mt_rand(0, 0xFFFF), mt_rand(0, 0xFFFF), // 16 bits for "time_mid" - mt_rand(0, 0xffff), + mt_rand(0, 0xFFFF), // 16 bits for "time_hi_and_version", // four most significant bits holds version number 4 - mt_rand(0, 0x0fff) | 0x4000, + mt_rand(0, 0x0FFF) | 0x4000, // 16 bits, 8 bits for "clk_seq_hi_res", // 8 bits for "clk_seq_low", // two most significant bits holds zero and one for variant DCE1.1 - mt_rand(0, 0x3fff) | 0x8000, + mt_rand(0, 0x3FFF) | 0x8000, // 48 bits for "node" - mt_rand(0, 0xffff), mt_rand(0, 0xffff), mt_rand(0, 0xffff) + mt_rand(0, 0xFFFF), mt_rand(0, 0xFFFF), mt_rand(0, 0xFFFF) ); } /** * Checks if a string is a valid UUID. - * - * @param string $uuid - * - * @return bool */ - public static function validateUUID($uuid) + public static function validateUUID(string $uuid): bool { return 0 !== preg_match( '/^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/i', diff --git a/lib/VCardConverter.php b/lib/VCardConverter.php index 04932fe67..88d74602c 100644 --- a/lib/VCardConverter.php +++ b/lib/VCardConverter.php @@ -2,6 +2,9 @@ namespace Sabre\VObject; +use Sabre\VObject\Property\Binary; +use Sabre\VObject\Property\Uri; + /** * This utility converts vcards from one version to another. * @@ -26,9 +29,9 @@ class VCardConverter * * If input and output version are identical, a clone is returned. * - * @param int $targetVersion + * @throws InvalidDataException */ - public function convert(Component\VCard $input, $targetVersion) + public function convert(Component\VCard $input, int $targetVersion): Component\VCard { $inputVersion = $input->getDocumentType(); if ($inputVersion === $targetVersion) { @@ -61,9 +64,9 @@ public function convert(Component\VCard $input, $targetVersion) /** * Handles conversion of a single property. * - * @param int $targetVersion + * @throws InvalidDataException */ - protected function convertProperty(Component\VCard $input, Component\VCard $output, Property $property, $targetVersion) + protected function convertProperty(Component\VCard $input, Component\VCard $output, Property $property, int $targetVersion): void { // Skipping these, those are automatically added. if (in_array($property->name, ['VERSION', 'PRODID'])) { @@ -91,14 +94,15 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp if (Document::VCARD30 === $targetVersion) { if ($property instanceof Property\Uri && in_array($property->name, ['PHOTO', 'LOGO', 'SOUND'])) { + /** @var Property\Uri $newProperty */ $newProperty = $this->convertUriToBinary($output, $newProperty); } elseif ($property instanceof Property\VCard\DateAndOrTime) { // In vCard 4, the birth year may be optional. This is not the // case for vCard 3. Apple has a workaround for this that // allows applications that support Apple's extension still - // omit birthyears in vCard 3, but applications that do not - // support this, will just use a random birthyear. We're - // choosing 1604 for the birthyear, because that's what apple + // omit birth years in vCard 3, but applications that do not + // support this, will just use a random birth year. We're + // choosing 1604 for the birth year, because that's what apple // uses. $parts = DateTimeParser::parseVCardDateTime($property->getValue()); if (is_null($parts['year'])) { @@ -140,6 +144,8 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp $newProperty = $output->createProperty('X-ADDRESSBOOKSERVER-KIND', 'GROUP'); break; } + } elseif ('MEMBER' === $property->name) { + $newProperty = $output->createProperty('X-ADDRESSBOOKSERVER-MEMBER', $property->getValue()); } } elseif (Document::VCARD40 === $targetVersion) { // These properties were removed in vCard 4.0 @@ -148,6 +154,7 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp } if ($property instanceof Property\Binary) { + /** @var Property\Binary $newProperty */ $newProperty = $this->convertBinaryToUri($output, $newProperty, $parameters); } elseif ($property instanceof Property\VCard\DateAndOrTime && isset($parameters['X-APPLE-OMIT-YEAR'])) { // If a property such as BDAY contained 'X-APPLE-OMIT-YEAR', @@ -173,6 +180,9 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp $newProperty = $output->createProperty('KIND', 'GROUP'); } break; + case 'X-ADDRESSBOOKSERVER-MEMBER': + $newProperty = $output->createProperty('MEMBER', $property->getValue()); + break; case 'X-ANNIVERSARY': $newProperty->name = 'ANNIVERSARY'; // If we already have an anniversary property with the same @@ -204,7 +214,7 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp } $newProperty->name = 'ANNIVERSARY'; break; - // Apple's per-property label system. + // Apple's per-property label system. case 'X-ABLABEL': if ('_$!!$_' === $newProperty->getValue()) { // We can safely remove these, as they are converted to @@ -226,7 +236,7 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp // Lastly, we need to see if there's a need for a VALUE parameter. // - // We can do that by instantiating a empty property with that name, and + // We can do that by instantiating an empty property with that name, and // seeing if the default valueType is identical to the current one. $tempProperty = $output->createProperty($newProperty->name); if ($tempProperty->getValueType() !== $newProperty->getValueType()) { @@ -241,15 +251,15 @@ protected function convertProperty(Component\VCard $input, Component\VCard $outp * * vCard 4.0 no longer supports BINARY properties. * - * @param Property\Uri $property the input property - * @param $parameters list of parameters that will eventually be added to - * the new property + * @param array $parameters list of parameters that will eventually be added to + * the new property * - * @return Property\Uri + * @throws InvalidDataException */ - protected function convertBinaryToUri(Component\VCard $output, Property\Binary $newProperty, array &$parameters) + protected function convertBinaryToUri(Component\VCard $output, Property\Binary $newProperty, array &$parameters): Uri { $value = $newProperty->getValue(); + /** @var Uri $newProperty */ $newProperty = $output->createProperty( $newProperty->name, null, // no value @@ -294,11 +304,11 @@ protected function convertBinaryToUri(Component\VCard $output, Property\Binary $ * be valid in vCard 3.0 as well, we should convert those to BINARY if * possible, to improve compatibility. * - * @param Property\Uri $property the input property + * @return Property\Binary|Property\Uri|null * - * @return Property\Binary|null + * @throws InvalidDataException */ - protected function convertUriToBinary(Component\VCard $output, Property\Uri $newProperty) + protected function convertUriToBinary(Component\VCard $output, Property\Uri $newProperty): Property { $value = $newProperty->getValue(); @@ -307,6 +317,7 @@ protected function convertUriToBinary(Component\VCard $output, Property\Uri $new return $newProperty; } + /** @var Binary $newProperty */ $newProperty = $output->createProperty( $newProperty->name, null, // no value @@ -342,7 +353,7 @@ protected function convertUriToBinary(Component\VCard $output, Property\Uri $new /** * Adds parameters to a new property for vCard 4.0. */ - protected function convertParameters40(Property $newProperty, array $parameters) + protected function convertParameters40(Property $newProperty, array $parameters): void { // Adding all parameters. foreach ($parameters as $param) { @@ -363,7 +374,7 @@ protected function convertParameters40(Property $newProperty, array $parameters) } } break; - // These no longer exist in vCard 4 + // These no longer exist in vCard 4 case 'ENCODING': case 'CHARSET': break; @@ -378,7 +389,7 @@ protected function convertParameters40(Property $newProperty, array $parameters) /** * Adds parameters to a new property for vCard 3.0. */ - protected function convertParameters30(Property $newProperty, array $parameters) + protected function convertParameters30(Property $newProperty, array $parameters): void { // Adding all parameters. foreach ($parameters as $param) { @@ -396,11 +407,11 @@ protected function convertParameters30(Property $newProperty, array $parameters) } break; - /* - * Converting PREF=1 to TYPE=PREF. - * - * Any other PREF numbers we'll drop. - */ + /* + * Converting PREF=1 to TYPE=PREF. + * + * Any other PREF numbers we'll drop. + */ case 'PREF': if ('1' == $param->getValue()) { $newProperty->add('TYPE', 'PREF'); diff --git a/lib/Version.php b/lib/Version.php index 6b7729caa..fd597c050 100644 --- a/lib/Version.php +++ b/lib/Version.php @@ -14,5 +14,5 @@ class Version /** * Full version number. */ - const VERSION = '4.28.0'; + public const VERSION = '4.28.0'; } diff --git a/lib/Writer.php b/lib/Writer.php index cbd22022e..504e38a7d 100644 --- a/lib/Writer.php +++ b/lib/Writer.php @@ -18,32 +18,24 @@ class Writer { /** * Serializes a vCard or iCalendar object. - * - * @return string */ - public static function write(Component $component) + public static function write(Component $component): string { return $component->serialize(); } /** * Serializes a jCal or jCard object. - * - * @param int $options - * - * @return string */ - public static function writeJson(Component $component, $options = 0) + public static function writeJson(Component $component, int $options = 0): string { return json_encode($component, $options); } /** * Serializes a xCal or xCard object. - * - * @return string */ - public static function writeXml(Component $component) + public static function writeXml(Component $component): string { $writer = new Xml\Writer(); $writer->openMemory(); diff --git a/lib/timezonedata/extrazones.php b/lib/timezonedata/extrazones.php index 711833520..8e477eb99 100644 --- a/lib/timezonedata/extrazones.php +++ b/lib/timezonedata/extrazones.php @@ -2,7 +2,7 @@ /** * The following list are extra timezones partially extracted from - * https://unicode-org.github.io/cldr-staging/charts/37/supplemental/zone_tzid.html + * https://unicode-org.github.io/cldr-staging/charts/37/supplemental/zone_tzid.html. */ return [ 'Acre' => 'America/Rio_Branco', diff --git a/lib/timezonedata/lotuszones.php b/lib/timezonedata/lotuszones.php index 4ba6e3cbe..684a0c972 100644 --- a/lib/timezonedata/lotuszones.php +++ b/lib/timezonedata/lotuszones.php @@ -40,7 +40,7 @@ // 'Mid-Atlantic' => 'Etc/GMT-2', // conflict with windows timezones. 'Azores' => 'Atlantic/Azores', 'Cape Verde' => 'Atlantic/Cape_Verde', - 'Greenwich' => 'Atlantic/Reykjavik', // No I'm serious.. Greenwich is not GMT. + 'Greenwich' => 'Atlantic/Reykjavik', // No I'm serious. Greenwich is not GMT. 'Morocco' => 'Africa/Casablanca', 'Central Europe' => 'Europe/Prague', 'Central European' => 'Europe/Sarajevo', diff --git a/tests/VObject/AttachIssueTest.php b/tests/VObject/AttachIssueTest.php index fb2b8b037..6f8981a37 100644 --- a/tests/VObject/AttachIssueTest.php +++ b/tests/VObject/AttachIssueTest.php @@ -6,7 +6,7 @@ class AttachIssueTest extends TestCase { - public function testRead() + public function testRead(): void { $event = <<assertEquals($event, $obj->serialize()); + self::assertEquals($event, $obj->serialize()); } } diff --git a/tests/VObject/BirthdayCalendarGeneratorTest.php b/tests/VObject/BirthdayCalendarGeneratorTest.php index d27362837..ac69d1f0b 100644 --- a/tests/VObject/BirthdayCalendarGeneratorTest.php +++ b/tests/VObject/BirthdayCalendarGeneratorTest.php @@ -8,7 +8,7 @@ class BirthdayCalendarGeneratorTest extends TestCase { use PHPUnitAssertions; - public function testVcardStringWithValidBirthday() + public function testVcardStringWithValidBirthday(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testArrayOfVcardStringsWithValidBirthdays() + public function testArrayOfVcardStringsWithValidBirthdays(): void { $generator = new BirthdayCalendarGenerator(); $input = []; @@ -97,13 +97,13 @@ public function testArrayOfVcardStringsWithValidBirthdays() $generator->setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testArrayOfVcardStringsWithValidBirthdaysViaConstructor() + public function testArrayOfVcardStringsWithValidBirthdaysViaConstructor(): void { $input = []; @@ -156,13 +156,13 @@ public function testArrayOfVcardStringsWithValidBirthdaysViaConstructor() $generator->setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardObjectWithValidBirthday() + public function testVcardObjectWithValidBirthday(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testArrayOfVcardObjectsWithValidBirthdays() + public function testArrayOfVcardObjectsWithValidBirthdays(): void { $generator = new BirthdayCalendarGenerator(); $input = []; @@ -257,13 +257,13 @@ public function testArrayOfVcardObjectsWithValidBirthdays() $generator->setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardStringWithValidBirthdayWithXAppleOmitYear() + public function testVcardStringWithValidBirthdayWithXAppleOmitYear(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardStringWithValidBirthdayWithoutYear() + public function testVcardStringWithValidBirthdayWithoutYear(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardStringWithInvalidBirthday() + public function testVcardStringWithInvalidBirthday(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardStringWithNoBirthday() + public function testVcardStringWithNoBirthday(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardStringWithValidBirthdayLocalized() + public function testVcardStringWithValidBirthdayLocalized(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setFormat('%1$s\'s Geburtstag'); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testVcardStringWithEmptyBirthdayProperty() + public function testVcardStringWithEmptyBirthdayProperty(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); } - public function testParseException() + public function testParseException(): void { $this->expectException(ParseException::class); $generator = new BirthdayCalendarGenerator(); @@ -471,7 +471,7 @@ public function testParseException() $generator->setObjects($input); } - public function testInvalidArgumentException() + public function testInvalidArgumentException(): void { $this->expectException(\InvalidArgumentException::class); $generator = new BirthdayCalendarGenerator(); @@ -488,7 +488,7 @@ public function testInvalidArgumentException() $generator->setObjects($input); } - public function testInvalidArgumentExceptionForPartiallyInvalidArray() + public function testInvalidArgumentExceptionForPartiallyInvalidArray(): void { $this->expectException(\InvalidArgumentException::class); $generator = new BirthdayCalendarGenerator(); @@ -513,7 +513,7 @@ public function testInvalidArgumentExceptionForPartiallyInvalidArray() $generator->setObjects($input); } - public function testBrokenVcardWithoutFN() + public function testBrokenVcardWithoutFN(): void { $generator = new BirthdayCalendarGenerator(); $input = <<setObjects($input); $output = $generator->getResult(); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $output ); diff --git a/tests/VObject/CliTest.php b/tests/VObject/CliTest.php index a4124b76b..c57d25226 100644 --- a/tests/VObject/CliTest.php +++ b/tests/VObject/CliTest.php @@ -11,10 +11,9 @@ */ class CliTest extends TestCase { - /** @var CliMock */ - private $cli; + private CliMock $cli; - private $sabreTempDir = __DIR__.'/../temp/'; + private string $sabreTempDir = __DIR__.'/../temp/'; public function setUp(): void { @@ -27,105 +26,105 @@ public function setUp(): void $this->cli->stdout = fopen('php://memory', 'r+'); } - public function testInvalidArg() + public function testInvalidArg(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', '--hi']) ); rewind($this->cli->stderr); - $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); + self::assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); } - public function testQuiet() + public function testQuiet(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', '-q']) ); - $this->assertTrue($this->cli->quiet); + self::assertTrue($this->cli->quiet); rewind($this->cli->stderr); - $this->assertEquals(0, strlen(stream_get_contents($this->cli->stderr))); + self::assertEquals(0, strlen(stream_get_contents($this->cli->stderr))); } - public function testHelp() + public function testHelp(): void { - $this->assertEquals( + self::assertEquals( 0, $this->cli->main(['vobject', '-h']) ); rewind($this->cli->stderr); - $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); + self::assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); } - public function testFormat() + public function testFormat(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', '--format=jcard']) ); rewind($this->cli->stderr); - $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); + self::assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); - $this->assertEquals('jcard', $this->cli->format); + self::assertEquals('jcard', $this->cli->format); } - public function testFormatInvalid() + public function testFormatInvalid(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', '--format=foo']) ); rewind($this->cli->stderr); - $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); + self::assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); - $this->assertNull($this->cli->format); + self::assertNull($this->cli->format); } - public function testInputFormatInvalid() + public function testInputFormatInvalid(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', '--inputformat=foo']) ); rewind($this->cli->stderr); - $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); + self::assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); - $this->assertNull($this->cli->format); + self::assertNull($this->cli->format); } - public function testNoInputFile() + public function testNoInputFile(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', 'color']) ); rewind($this->cli->stderr); - $this->assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); + self::assertTrue(strlen(stream_get_contents($this->cli->stderr)) > 100); } - public function testTooManyArgs() + public function testTooManyArgs(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', 'color', 'a', 'b', 'c']) ); } - public function testUnknownCommand() + public function testUnknownCommand(): void { - $this->assertEquals( + self::assertEquals( 1, $this->cli->main(['vobject', 'foo', '-']) ); } - public function testConvertJson() + public function testConvertJson(): void { $inputStream = fopen('php://memory', 'r+'); @@ -135,24 +134,24 @@ public function testConvertJson() FN:Cowboy Henk END:VCARD ICS - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 0, $this->cli->main(['vobject', 'convert', '--format=json', '-']) ); rewind($this->cli->stdout); $version = Version::VERSION; - $this->assertEquals( + self::assertEquals( '["vcard",[["version",{},"text","4.0"],["prodid",{},"text","-\/\/Sabre\/\/Sabre VObject '.$version.'\/\/EN"],["fn",{},"text","Cowboy Henk"]]]', stream_get_contents($this->cli->stdout) ); } - public function testConvertJCardPretty() + public function testConvertJCardPretty(): void { if (version_compare(PHP_VERSION, '5.4.0') < 0) { $this->markTestSkipped('This test required PHP 5.4.0'); @@ -166,11 +165,11 @@ public function testConvertJCardPretty() FN:Cowboy Henk END:VCARD ICS - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 0, $this->cli->main(['vobject', 'convert', '--format=jcard', '--pretty', '-']) ); @@ -187,13 +186,13 @@ public function testConvertJCardPretty() "versi JCARD; - $this->assertStringStartsWith( + self::assertStringStartsWith( $expected, stream_get_contents($this->cli->stdout) ); } - public function testConvertJCalFail() + public function testConvertJCalFail(): void { $inputStream = fopen('php://memory', 'r+'); @@ -203,17 +202,17 @@ public function testConvertJCalFail() FN:Cowboy Henk END:VCARD ICS - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'convert', '--format=jcal', '--inputformat=mimedir', '-']) ); } - public function testConvertMimeDir() + public function testConvertMimeDir(): void { $inputStream = fopen('php://memory', 'r+'); @@ -248,11 +247,11 @@ public function testConvertMimeDir() ] ] JCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 0, $this->cli->main(['vobject', 'convert', '--format=mimedir', '--inputformat=json', '--pretty', '-']) ); @@ -267,39 +266,39 @@ public function testConvertMimeDir() VCF; - $this->assertEquals( + self::assertEquals( strtr($expected, ["\n" => "\r\n"]), stream_get_contents($this->cli->stdout) ); } - public function testConvertDefaultFormats() + public function testConvertDefaultFormats(): void { $outputFile = $this->sabreTempDir.'bar.json'; - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'convert', 'foo.json', $outputFile]) ); - $this->assertEquals('json', $this->cli->inputFormat); - $this->assertEquals('json', $this->cli->format); + self::assertEquals('json', $this->cli->inputFormat); + self::assertEquals('json', $this->cli->format); } - public function testConvertDefaultFormats2() + public function testConvertDefaultFormats2(): void { $outputFile = $this->sabreTempDir.'bar.ics'; - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'convert', 'foo.ics', $outputFile]) ); - $this->assertEquals('mimedir', $this->cli->inputFormat); - $this->assertEquals('mimedir', $this->cli->format); + self::assertEquals('mimedir', $this->cli->inputFormat); + self::assertEquals('mimedir', $this->cli->format); } - public function testVCard3040() + public function testVCard3040(): void { $inputStream = fopen('php://memory', 'r+'); @@ -311,11 +310,11 @@ public function testVCard3040() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 0, $this->cli->main(['vobject', 'convert', '--format=vcard40', '--pretty', '-']) ); @@ -332,13 +331,13 @@ public function testVCard3040() VCF; - $this->assertEquals( + self::assertEquals( strtr($expected, ["\n" => "\r\n"]), stream_get_contents($this->cli->stdout) ); } - public function testVCard4030() + public function testVCard4030(): void { $inputStream = fopen('php://memory', 'r+'); @@ -350,11 +349,11 @@ public function testVCard4030() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 0, $this->cli->main(['vobject', 'convert', '--format=vcard30', '--pretty', '-']) ); @@ -371,13 +370,13 @@ public function testVCard4030() VCF; - $this->assertEquals( + self::assertEquals( strtr($expected, ["\n" => "\r\n"]), stream_get_contents($this->cli->stdout) ); } - public function testVCard4021() + public function testVCard4021(): void { $inputStream = fopen('php://memory', 'r+'); @@ -389,17 +388,17 @@ public function testVCard4021() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'convert', '--format=vcard21', '--pretty', '-']) ); } - public function testValidate() + public function testValidate(): void { $inputStream = fopen('php://memory', 'r+'); @@ -412,18 +411,18 @@ public function testValidate() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; $result = $this->cli->main(['vobject', 'validate', '-']); - $this->assertEquals( + self::assertEquals( 0, $result ); } - public function testValidateFail() + public function testValidateFail(): void { $inputStream = fopen('php://memory', 'r+'); @@ -433,17 +432,17 @@ public function testValidateFail() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; // vCard 2.0 is not supported yet, so this returns a failure. - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'validate', '-']) ); } - public function testValidateFail2() + public function testValidateFail2(): void { $inputStream = fopen('php://memory', 'r+'); @@ -453,17 +452,17 @@ public function testValidateFail2() END:VCALENDAR VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'validate', '-']) ); } - public function testRepair() + public function testRepair(): void { $inputStream = fopen('php://memory', 'r+'); @@ -473,11 +472,11 @@ public function testRepair() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; - $this->assertEquals( + self::assertEquals( 2, $this->cli->main(['vobject', 'repair', '-']) ); @@ -485,16 +484,10 @@ public function testRepair() rewind($this->cli->stdout); $regularExpression = "/^BEGIN:VCARD\r\nVERSION:2.1\r\nUID:[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}\r\nEND:VCARD\r\n$/"; $data = stream_get_contents($this->cli->stdout); - // ToDo: when we do not need to run phpunit 7 or 8, remove this 'if' block and just use - // the new assertMatchesRegularExpression that exists since phpunit 9. - if (method_exists($this, 'assertMatchesRegularExpression')) { - $this->assertMatchesRegularExpression($regularExpression, $data); - } else { - $this->assertRegExp($regularExpression, $data); - } + self::assertMatchesRegularExpression($regularExpression, $data); } - public function testRepairNothing() + public function testRepairNothing(): void { $inputStream = fopen('php://memory', 'r+'); @@ -510,7 +503,7 @@ public function testRepairNothing() END:VCALENDAR VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; @@ -519,7 +512,7 @@ public function testRepairNothing() rewind($this->cli->stderr); $error = stream_get_contents($this->cli->stderr); - $this->assertEquals( + self::assertEquals( 0, $result, "This should have been error free. stderr output:\n".$error @@ -532,7 +525,7 @@ public function testRepairNothing() * * The colorizer is not a critical component, it's mostly a debugging tool. */ - public function testColorCalendar() + public function testColorCalendar(): void { $inputStream = fopen('php://memory', 'r+'); @@ -556,7 +549,7 @@ public function testColorCalendar() END:VCALENDAR VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; @@ -565,7 +558,7 @@ public function testColorCalendar() rewind($this->cli->stderr); $error = stream_get_contents($this->cli->stderr); - $this->assertEquals( + self::assertEquals( 0, $result, "This should have been error free. stderr output:\n".$error @@ -578,7 +571,7 @@ public function testColorCalendar() * * The colorizer is not a critical component, it's mostly a debugging tool. */ - public function testColorVCard() + public function testColorVCard(): void { $inputStream = fopen('php://memory', 'r+'); @@ -597,7 +590,7 @@ public function testColorVCard() END:VCARD VCARD - ); + ); rewind($inputStream); $this->cli->stdin = $inputStream; @@ -606,7 +599,7 @@ public function testColorVCard() rewind($this->cli->stderr); $error = stream_get_contents($this->cli->stderr); - $this->assertEquals( + self::assertEquals( 0, $result, "This should have been error free. stderr output:\n".$error @@ -616,19 +609,32 @@ public function testColorVCard() class CliMock extends Cli { - public $quiet = false; + public bool $quiet = false; - public $format; + public ?string $format = null; - public $pretty; + public bool $pretty = false; + /** + * stdin. + * + * @var resource + */ public $stdin; + /** + * output stream. + * + * @var resource + */ public $stdout; + /** + * stderr. + * + * @var resource + */ public $stderr; - public $inputFormat; - - public $outputFormat; + public ?string $inputFormat = null; } diff --git a/tests/VObject/Component/AvailableTest.php b/tests/VObject/Component/AvailableTest.php index bf0a6716f..98202ffcb 100644 --- a/tests/VObject/Component/AvailableTest.php +++ b/tests/VObject/Component/AvailableTest.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Reader; @@ -13,7 +11,7 @@ */ class AvailableTest extends TestCase { - public function testAvailableComponent() + public function testAvailableComponent(): void { $vcal = <<assertInstanceOf(Available::class, $document->AVAILABLE); + self::assertInstanceOf(Available::class, $document->AVAILABLE); } - public function testGetEffectiveStartEnd() + public function testGetEffectiveStartEnd(): void { $vcal = <<assertEquals( + $tz = new \DateTimeZone('UTC'); + self::assertEquals( [ - new DateTimeImmutable('2015-07-17 16:22:00', $tz), - new DateTimeImmutable('2015-07-17 17:22:00', $tz), + new \DateTimeImmutable('2015-07-17 16:22:00', $tz), + new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], $document->AVAILABLE->getEffectiveStartEnd() ); } - public function testGetEffectiveStartEndDuration() + public function testGetEffectiveStartEndDuration(): void { $vcal = <<assertEquals( + $tz = new \DateTimeZone('UTC'); + self::assertEquals( [ - new DateTimeImmutable('2015-07-17 16:22:00', $tz), - new DateTimeImmutable('2015-07-17 17:22:00', $tz), + new \DateTimeImmutable('2015-07-17 16:22:00', $tz), + new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], $document->AVAILABLE->getEffectiveStartEnd() ); diff --git a/tests/VObject/Component/VAlarmTest.php b/tests/VObject/Component/VAlarmTest.php index 2823d16da..4694d6363 100644 --- a/tests/VObject/Component/VAlarmTest.php +++ b/tests/VObject/Component/VAlarmTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\InvalidDataException; use Sabre\VObject\Reader; @@ -12,12 +11,12 @@ class VAlarmTest extends TestCase /** * @dataProvider timeRangeTestData */ - public function testInTimeRange(VAlarm $valarm, $start, $end, $outcome) + public function testInTimeRange(VAlarm $valarm, \DateTime $start, \DateTime $end, bool $outcome): void { - $this->assertEquals($outcome, $valarm->isInTimeRange($start, $end)); + self::assertEquals($outcome, $valarm->isInTimeRange($start, $end)); } - public function timeRangeTestData() + public function timeRangeTestData(): array { $tests = []; @@ -29,8 +28,8 @@ public function timeRangeTestData() $calendar->createProperty('TRIGGER', '20120312T130000Z', ['VALUE' => 'DATE-TIME']) ); - $tests[] = [$valarm1, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-04-01 01:00:00'), true]; - $tests[] = [$valarm1, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false]; + $tests[] = [$valarm1, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true]; + $tests[] = [$valarm1, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-03-10 01:00:00'), false]; // Relation to start time of event $valarm2 = $calendar->createComponent('VALARM'); @@ -42,8 +41,8 @@ public function timeRangeTestData() $vevent2->DTSTART = '20120313T130000Z'; $vevent2->add($valarm2); - $tests[] = [$valarm2, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-04-01 01:00:00'), true]; - $tests[] = [$valarm2, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false]; + $tests[] = [$valarm2, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true]; + $tests[] = [$valarm2, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-03-10 01:00:00'), false]; // Relation to end time of event $valarm3 = $calendar->createComponent('VALARM'); @@ -54,8 +53,8 @@ public function timeRangeTestData() $vevent3->DTEND = '20120401T130000Z'; $vevent3->add($valarm3); - $tests[] = [$valarm3, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), false]; - $tests[] = [$valarm3, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true]; + $tests[] = [$valarm3, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false]; + $tests[] = [$valarm3, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), true]; // Relation to end time of todo $valarm4 = $calendar->createComponent('VALARM'); @@ -68,8 +67,8 @@ public function timeRangeTestData() $vtodo4->DUE = '20120401T130000Z'; $vtodo4->add($valarm4); - $tests[] = [$valarm4, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), false]; - $tests[] = [$valarm4, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true]; + $tests[] = [$valarm4, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false]; + $tests[] = [$valarm4, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), true]; // Relation to start time of event + repeat $valarm5 = $calendar->createComponent('VALARM'); @@ -82,7 +81,7 @@ public function timeRangeTestData() $vevent5->DTSTART = '20120301T130000Z'; $vevent5->add($valarm5); - $tests[] = [$valarm5, new DateTime('2012-03-09 01:00:00'), new DateTime('2012-03-10 01:00:00'), true]; + $tests[] = [$valarm5, new \DateTime('2012-03-09 01:00:00'), new \DateTime('2012-03-10 01:00:00'), true]; // Relation to start time of event + duration, but no repeat $valarm6 = $calendar->createComponent('VALARM'); @@ -94,8 +93,8 @@ public function timeRangeTestData() $vevent6->DTSTART = '20120313T130000Z'; $vevent6->add($valarm6); - $tests[] = [$valarm6, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-04-01 01:00:00'), true]; - $tests[] = [$valarm6, new DateTime('2012-03-01 01:00:00'), new DateTime('2012-03-10 01:00:00'), false]; + $tests[] = [$valarm6, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-04-01 01:00:00'), true]; + $tests[] = [$valarm6, new \DateTime('2012-03-01 01:00:00'), new \DateTime('2012-03-10 01:00:00'), false]; // Relation to end time of event (DURATION instead of DTEND) $valarm7 = $calendar->createComponent('VALARM'); @@ -108,8 +107,8 @@ public function timeRangeTestData() $vevent7->DURATION = 'P30D'; $vevent7->add($valarm7); - $tests[] = [$valarm7, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), false]; - $tests[] = [$valarm7, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), true]; + $tests[] = [$valarm7, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), false]; + $tests[] = [$valarm7, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), true]; // Relation to end time of event (No DTEND or DURATION) $valarm7 = $calendar->createComponent('VALARM'); @@ -121,13 +120,13 @@ public function timeRangeTestData() $vevent7->DTSTART = '20120301T130000Z'; $vevent7->add($valarm7); - $tests[] = [$valarm7, new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00'), true]; - $tests[] = [$valarm7, new DateTime('2012-03-25 01:00:00'), new DateTime('2012-04-05 01:00:00'), false]; + $tests[] = [$valarm7, new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00'), true]; + $tests[] = [$valarm7, new \DateTime('2012-03-25 01:00:00'), new \DateTime('2012-04-05 01:00:00'), false]; return $tests; } - public function testInTimeRangeInvalidComponent() + public function testInTimeRangeInvalidComponent(): void { $this->expectException(InvalidDataException::class); $calendar = new VCalendar(); @@ -138,13 +137,13 @@ public function testInTimeRangeInvalidComponent() $vjournal = $calendar->createComponent('VJOURNAL'); $vjournal->add($valarm); - $valarm->isInTimeRange(new DateTime('2012-02-25 01:00:00'), new DateTime('2012-03-05 01:00:00')); + $valarm->isInTimeRange(new \DateTime('2012-02-25 01:00:00'), new \DateTime('2012-03-05 01:00:00')); } /** * This bug was found and reported on the mailing list. */ - public function testInTimeRangeBuggy() + public function testInTimeRangeBuggy(): void { $input = <<assertTrue($vobj->VTODO->VALARM->isInTimeRange(new \DateTime('2012-10-01 00:00:00'), new \DateTime('2012-11-01 00:00:00'))); + self::assertTrue($vobj->VTODO->VALARM->isInTimeRange(new \DateTime('2012-10-01 00:00:00'), new \DateTime('2012-11-01 00:00:00'))); } } diff --git a/tests/VObject/Component/VAvailabilityTest.php b/tests/VObject/Component/VAvailabilityTest.php index edd06b02b..263eeebda 100644 --- a/tests/VObject/Component/VAvailabilityTest.php +++ b/tests/VObject/Component/VAvailabilityTest.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject; use Sabre\VObject\Reader; @@ -14,7 +12,7 @@ */ class VAvailabilityTest extends TestCase { - public function testVAvailabilityComponent() + public function testVAvailabilityComponent(): void { $vcal = <<assertInstanceOf(VAvailability::class, $document->VAVAILABILITY); + self::assertInstanceOf(VAvailability::class, $document->VAVAILABILITY); } - public function testGetEffectiveStartEnd() + public function testGetEffectiveStartEnd(): void { $vcal = <<assertEquals( + $tz = new \DateTimeZone('UTC'); + self::assertEquals( [ - new DateTimeImmutable('2015-07-17 16:22:00', $tz), - new DateTimeImmutable('2015-07-17 17:22:00', $tz), + new \DateTimeImmutable('2015-07-17 16:22:00', $tz), + new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], $document->VAVAILABILITY->getEffectiveStartEnd() ); } - public function testGetEffectiveStartDuration() + public function testGetEffectiveStartDuration(): void { $vcal = <<assertEquals( + $tz = new \DateTimeZone('UTC'); + self::assertEquals( [ - new DateTimeImmutable('2015-07-17 16:22:00', $tz), - new DateTimeImmutable('2015-07-17 17:22:00', $tz), + new \DateTimeImmutable('2015-07-17 16:22:00', $tz), + new \DateTimeImmutable('2015-07-17 17:22:00', $tz), ], $document->VAVAILABILITY->getEffectiveStartEnd() ); } - public function testGetEffectiveStartEndUnbound() + public function testGetEffectiveStartEndUnbound(): void { $vcal = <<assertEquals( + self::assertEquals( [ null, null, @@ -90,7 +88,7 @@ public function testGetEffectiveStartEndUnbound() ); } - public function testIsInTimeRangeUnbound() + public function testIsInTimeRangeUnbound(): void { $vcal = <<assertTrue( - $document->VAVAILABILITY->isInTimeRange(new DateTimeImmutable('2015-07-17'), new DateTimeImmutable('2015-07-18')) + self::assertTrue( + $document->VAVAILABILITY->isInTimeRange(new \DateTimeImmutable('2015-07-17'), new \DateTimeImmutable('2015-07-18')) ); } - public function testIsInTimeRangeOutside() + public function testIsInTimeRangeOutside(): void { $vcal = <<assertFalse( - $document->VAVAILABILITY->isInTimeRange(new DateTimeImmutable('2015-07-17'), new DateTimeImmutable('2015-07-18')) + self::assertFalse( + $document->VAVAILABILITY->isInTimeRange(new \DateTimeImmutable('2015-07-17'), new \DateTimeImmutable('2015-07-18')) ); } - public function testRFCxxxSection3Part1AvailabilitypropRequired() + public function testRFCxxxSection3Part1AvailabilityPropRequired(): void { // UID and DTSTAMP are present. - $this->assertIsValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsValid(Reader::read($this->template($properties))); + self::assertIsValid(Reader::read($this->template($properties))); // We duplicate each one to see if it fails. foreach ($properties as $property) { - $this->assertIsNotValid(Reader::read($this->template([ + self::assertIsNotValid(Reader::read($this->template([ $property, $property, ]))); } } - public function testRFCxxxSection3Part1AvailabilitypropDtendDuration() + public function testRFCxxxSection3Part1AvailabilityPropDtendDuration(): void { // Only DTEND. - $this->assertIsValid(Reader::read($this->template([ + self::assertIsValid(Reader::read($this->template([ 'DTEND:21111005T133225Z', ]))); // Only DURATION. - $this->assertIsValid(Reader::read($this->template([ + self::assertIsValid(Reader::read($this->template([ 'DURATION:PT1H', ]))); // Both (not allowed). - $this->assertIsNotValid(Reader::read($this->template([ + self::assertIsNotValid(Reader::read($this->template([ 'DTEND:21111005T133225Z', 'DURATION:PT1H', ]))); } - public function testAvailableSubComponent() + public function testAvailableSubComponent(): void { $vcal = <<assertInstanceOf(Available::class, $document->VAVAILABILITY->AVAILABLE); + self::assertInstanceOf(Available::class, $document->VAVAILABILITY->AVAILABLE); } - public function testRFCxxxSection3Part1AvailablepropRequired() + public function testRFCxxxSection3Part1AvailablePropRequired(): void { // UID, DTSTAMP and DTSTART are present. - $this->assertIsValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsNotValid(Reader::read( -<<assertIsValid(Reader::read($this->templateAvailable([ + self::assertIsValid(Reader::read($this->templateAvailable([ 'DTEND:21111005T133225Z', ]))); // Only DURATION. - $this->assertIsValid(Reader::read($this->templateAvailable([ + self::assertIsValid(Reader::read($this->templateAvailable([ 'DURATION:PT1H', ]))); // Both (not allowed). - $this->assertIsNotValid(Reader::read($this->templateAvailable([ + self::assertIsNotValid(Reader::read($this->templateAvailable([ 'DTEND:21111005T133225Z', 'DURATION:PT1H', ]))); } - public function testRFCxxxSection3Part1AvailableOptionalOnce() + public function testRFCxxxSection3Part1AvailableOptionalOnce(): void { $properties = [ 'CREATED:20111005T135125Z', @@ -362,20 +360,20 @@ public function testRFCxxxSection3Part1AvailableOptionalOnce() ]; // They are all present, only once. - $this->assertIsValid(Reader::read($this->templateAvailable($properties))); + self::assertIsValid(Reader::read($this->templateAvailable($properties))); // We duplicate each one to see if it fails. foreach ($properties as $property) { - $this->assertIsNotValid(Reader::read($this->templateAvailable([ + self::assertIsNotValid(Reader::read($this->templateAvailable([ $property, $property, ]))); } } - public function testRFCxxxSection3Part2() + public function testRFCxxxSection3Part2(): void { - $this->assertEquals( + self::assertEquals( 'BUSY', Reader::read($this->templateAvailable([ 'BUSYTYPE:BUSY', @@ -386,7 +384,7 @@ public function testRFCxxxSection3Part2() ->getValue() ); - $this->assertEquals( + self::assertEquals( 'BUSY-UNAVAILABLE', Reader::read($this->templateAvailable([ 'BUSYTYPE:BUSY-UNAVAILABLE', @@ -397,7 +395,7 @@ public function testRFCxxxSection3Part2() ->getValue() ); - $this->assertEquals( + self::assertEquals( 'BUSY-TENTATIVE', Reader::read($this->templateAvailable([ 'BUSYTYPE:BUSY-TENTATIVE', @@ -409,19 +407,19 @@ public function testRFCxxxSection3Part2() ); } - protected function assertIsValid(VObject\Document $document) + protected function assertIsValid(VObject\Document $document): void { $validationResult = $document->validate(); if ($validationResult) { $messages = array_map(function ($item) { return $item['message']; }, $validationResult); $this->fail('Failed to assert that the supplied document is a valid document. Validation messages: '.implode(', ', $messages)); } - $this->assertEmpty($document->validate()); + self::assertEmpty($document->validate()); } - protected function assertIsNotValid(VObject\Document $document) + protected function assertIsNotValid(VObject\Document $document): void { - $this->assertNotEmpty($document->validate()); + self::assertNotEmpty($document->validate()); } protected function template(array $properties) @@ -438,7 +436,7 @@ protected function template(array $properties) END:VAVAILABILITY END:VCALENDAR VCAL -, + , $properties ); } @@ -462,7 +460,7 @@ protected function templateAvailable(array $properties) END:VAVAILABILITY END:VCALENDAR VCAL -, + , $properties ); } diff --git a/tests/VObject/Component/VCalendarTest.php b/tests/VObject/Component/VCalendarTest.php index d34e12d2b..1893a9ac7 100644 --- a/tests/VObject/Component/VCalendarTest.php +++ b/tests/VObject/Component/VCalendarTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Component; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject; use Sabre\VObject\InvalidDataException; @@ -14,11 +13,11 @@ class VCalendarTest extends TestCase /** * @dataProvider expandData */ - public function testExpand($input, $output, $timeZone = 'UTC', $start = '2011-12-01', $end = '2011-12-31') + public function testExpand(string $input, string $output, string $timeZone = 'UTC', string $start = '2011-12-01', string $end = '2011-12-31'): void { $vcal = VObject\Reader::read($input); - $timeZone = new DateTimeZone($timeZone); + $timeZone = new \DateTimeZone($timeZone); $vcal = $vcal->expand( new \DateTime($start), @@ -29,10 +28,10 @@ public function testExpand($input, $output, $timeZone = 'UTC', $start = '2011-12 // This will normalize the output $output = VObject\Reader::read($output)->serialize(); - $this->assertVObjectEqualsVObject($output, $vcal->serialize()); + self::assertVObjectEqualsVObject($output, $vcal->serialize()); } - public function expandData() + public function expandData(): array { $tests = []; @@ -331,7 +330,7 @@ public function expandData() return $tests; } - public function testBrokenEventExpand() + public function testBrokenEventExpand(): void { $this->expectException(InvalidDataException::class); $input = 'BEGIN:VCALENDAR @@ -357,7 +356,7 @@ public function testBrokenEventExpand() * * @medium */ - public function testEventExpandYearly() + public function testEventExpandYearly(): void { $input = 'BEGIN:VCALENDAR BEGIN:VEVENT @@ -374,17 +373,17 @@ public function testEventExpandYearly() new \DateTime('2023-01-01') ); - $this->assertCount(7, $events->VEVENT); + self::assertCount(7, $events->VEVENT); } - public function testGetDocumentType() + public function testGetDocumentType(): void { $vcard = new VCalendar(); $vcard->VERSION = '2.0'; - $this->assertEquals(VCalendar::ICALENDAR20, $vcard->getDocumentType()); + self::assertEquals(VCalendar::ICALENDAR20, $vcard->getDocumentType()); } - public function testValidateCorrect() + public function testValidateCorrect(): void { $input = 'BEGIN:VCALENDAR CALSCALE:GREGORIAN @@ -399,10 +398,10 @@ public function testValidateCorrect() '; $vcal = VObject\Reader::read($input); - $this->assertEquals([], $vcal->validate(), 'Got an error'); + self::assertEquals([], $vcal->validate(), 'Got an error'); } - public function testValidateNoVersion() + public function testValidateNoVersion(): void { $input = 'BEGIN:VCALENDAR CALSCALE:GREGORIAN @@ -416,10 +415,10 @@ public function testValidateNoVersion() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(1, count($vcal->validate())); + self::assertCount(1, $vcal->validate()); } - public function testValidateWrongVersion() + public function testValidateWrongVersion(): void { $input = 'BEGIN:VCALENDAR CALSCALE:GREGORIAN @@ -434,10 +433,10 @@ public function testValidateWrongVersion() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(1, count($vcal->validate())); + self::assertCount(1, $vcal->validate()); } - public function testValidateNoProdId() + public function testValidateNoProdId(): void { $input = 'BEGIN:VCALENDAR CALSCALE:GREGORIAN @@ -451,10 +450,10 @@ public function testValidateNoProdId() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(1, count($vcal->validate())); + self::assertCount(1, $vcal->validate()); } - public function testValidateDoubleCalScale() + public function testValidateDoubleCalScale(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -470,10 +469,10 @@ public function testValidateDoubleCalScale() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(1, count($vcal->validate())); + self::assertCount(1, $vcal->validate()); } - public function testValidateDoubleMethod() + public function testValidateDoubleMethod(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -489,10 +488,10 @@ public function testValidateDoubleMethod() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(1, count($vcal->validate())); + self::assertCount(1, $vcal->validate()); } - public function testValidateTwoMasterEvents() + public function testValidateTwoMasterEvents(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -512,10 +511,10 @@ public function testValidateTwoMasterEvents() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(1, count($vcal->validate())); + self::assertCount(1, $vcal->validate()); } - public function testValidateOneMasterEvent() + public function testValidateOneMasterEvent(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -536,10 +535,10 @@ public function testValidateOneMasterEvent() '; $vcal = VObject\Reader::read($input); - $this->assertEquals(0, count($vcal->validate())); + self::assertCount(0, $vcal->validate()); } - public function testGetBaseComponent() + public function testGetBaseComponent(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -563,10 +562,10 @@ public function testGetBaseComponent() $vcal = VObject\Reader::read($input); $result = $vcal->getBaseComponent(); - $this->assertEquals('test', $result->SUMMARY->getValue()); + self::assertEquals('test', $result->SUMMARY->getValue()); } - public function testGetBaseComponentNoResult() + public function testGetBaseComponentNoResult(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -591,10 +590,10 @@ public function testGetBaseComponentNoResult() $vcal = VObject\Reader::read($input); $result = $vcal->getBaseComponent(); - $this->assertNull($result); + self::assertNull($result); } - public function testGetBaseComponentWithFilter() + public function testGetBaseComponentWithFilter(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -618,10 +617,10 @@ public function testGetBaseComponentWithFilter() $vcal = VObject\Reader::read($input); $result = $vcal->getBaseComponent('VEVENT'); - $this->assertEquals('test', $result->SUMMARY->getValue()); + self::assertEquals('test', $result->SUMMARY->getValue()); } - public function testGetBaseComponentWithFilterNoResult() + public function testGetBaseComponentWithFilterNoResult(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -638,10 +637,10 @@ public function testGetBaseComponentWithFilterNoResult() $vcal = VObject\Reader::read($input); $result = $vcal->getBaseComponent('VEVENT'); - $this->assertNull($result); + self::assertNull($result); } - public function testNoComponents() + public function testNoComponents(): void { $input = <<assertValidate( + self::assertValidate( $input, 0, 3, - 'An iCalendar object must have at least 1 component.' + 'An iCalendar object must have at least 1 component.' ); } - public function testCalDAVNoComponents() + public function testCalDAVNoComponents(): void { $input = <<assertValidate( + self::assertValidate( $input, VCalendar::PROFILE_CALDAV, 3, - 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).' + 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).' ); } - public function testCalDAVMultiUID() + public function testCalDAVMultiUID(): void { $input = <<assertValidate( + self::assertValidate( $input, VCalendar::PROFILE_CALDAV, 3, - 'A calendar object on a CalDAV server may only have components with the same UID.' + 'A calendar object on a CalDAV server may only have components with the same UID.' ); } - public function testCalDAVMultiComponent() + public function testCalDAVMultiComponent(): void { $input = <<assertValidate( + self::assertValidate( $input, VCalendar::PROFILE_CALDAV, 3, - 'A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL).' + 'A calendar object on a CalDAV server may only have 1 type of component (VEVENT, VTODO or VJOURNAL).' ); } - public function testCalDAVMETHOD() + public function testCalDAVMETHOD(): void { $input = <<assertValidate( + self::assertValidate( $input, VCalendar::PROFILE_CALDAV, 3, - 'A calendar object on a CalDAV server MUST NOT have a METHOD property.' + 'A calendar object on a CalDAV server MUST NOT have a METHOD property.' ); } - public function assertValidate($ics, $options, $expectedLevel, $expectedMessage = null) + public function assertValidate($ics, $options, $expectedLevel, string $expectedMessage = null): void { $vcal = VObject\Reader::read($ics); $result = $vcal->validate($options); - $this->assertValidateResult($result, $expectedLevel, $expectedMessage); + self::assertValidateResult($result, $expectedLevel, $expectedMessage); } - public function assertValidateResult($input, $expectedLevel, $expectedMessage = null) + public function assertValidateResult($input, $expectedLevel, string $expectedMessage = null): void { $messages = []; foreach ($input as $warning) { @@ -773,12 +772,12 @@ public function assertValidateResult($input, $expectedLevel, $expectedMessage = } if (0 === $expectedLevel) { - $this->assertEquals(0, count($input), 'No validation messages were expected. We got: '.implode(', ', $messages)); + self::assertCount(0, $input, 'No validation messages were expected. We got: '.implode(', ', $messages)); } else { - $this->assertEquals(1, count($input), 'We expected exactly 1 validation message, We got: '.implode(', ', $messages)); + self::assertCount(1, $input, 'We expected exactly 1 validation message, We got: '.implode(', ', $messages)); - $this->assertEquals($expectedMessage, $input[0]['message']); - $this->assertEquals($expectedLevel, $input[0]['level']); + self::assertEquals($expectedMessage, $input[0]['message']); + self::assertEquals($expectedLevel, $input[0]['level']); } } } diff --git a/tests/VObject/Component/VCardTest.php b/tests/VObject/Component/VCardTest.php index d8e6110b6..b71b30856 100644 --- a/tests/VObject/Component/VCardTest.php +++ b/tests/VObject/Component/VCardTest.php @@ -10,7 +10,7 @@ class VCardTest extends TestCase /** * @dataProvider validateData */ - public function testValidate($input, $expectedWarnings, $expectedRepairedOutput) + public function testValidate(string $input, array $expectedWarnings, string $expectedRepairedOutput): void { $vcard = VObject\Reader::read($input); @@ -21,17 +21,17 @@ public function testValidate($input, $expectedWarnings, $expectedRepairedOutput) $warnMsg[] = $warning['message']; } - $this->assertEquals($expectedWarnings, $warnMsg); + self::assertEquals($expectedWarnings, $warnMsg); $vcard->validate(VObject\Component::REPAIR); - $this->assertEquals( + self::assertEquals( $expectedRepairedOutput, $vcard->serialize() ); } - public function validateData() + public function validateData(): array { $tests = []; @@ -92,6 +92,14 @@ public function validateData() ], "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nORG:Acme Co.\r\nFN:Acme Co.\r\nEND:VCARD\r\n", ]; + // No FN, NICKNAME fallback + $tests[] = [ + "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nNICKNAME:JohnDoe\r\nEND:VCARD\r\n", + [ + 'The FN property must appear in the VCARD component exactly 1 time', + ], + "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nNICKNAME:JohnDoe\r\nFN:JohnDoe\r\nEND:VCARD\r\n", + ]; // No FN, EMAIL fallback $tests[] = [ "BEGIN:VCARD\r\nVERSION:4.0\r\nUID:foo\r\nEMAIL:1@example.org\r\nEND:VCARD\r\n", @@ -104,25 +112,25 @@ public function validateData() return $tests; } - public function testGetDocumentType() + public function testGetDocumentType(): void { $vcard = new VCard([], false); $vcard->VERSION = '2.1'; - $this->assertEquals(VCard::VCARD21, $vcard->getDocumentType()); + self::assertEquals(VCard::VCARD21, $vcard->getDocumentType()); $vcard = new VCard([], false); $vcard->VERSION = '3.0'; - $this->assertEquals(VCard::VCARD30, $vcard->getDocumentType()); + self::assertEquals(VCard::VCARD30, $vcard->getDocumentType()); $vcard = new VCard([], false); $vcard->VERSION = '4.0'; - $this->assertEquals(VCard::VCARD40, $vcard->getDocumentType()); + self::assertEquals(VCard::VCARD40, $vcard->getDocumentType()); $vcard = new VCard([], false); - $this->assertEquals(VCard::UNKNOWN, $vcard->getDocumentType()); + self::assertEquals(VCard::UNKNOWN, $vcard->getDocumentType()); } - public function testGetByType() + public function testGetByType(): void { $vcard = <<assertEquals('1@example.org', $vcard->getByType('EMAIL', 'home')->getValue()); - $this->assertEquals('2@example.org', $vcard->getByType('EMAIL', 'work')->getValue()); - $this->assertNull($vcard->getByType('EMAIL', 'non-existent')); - $this->assertNull($vcard->getByType('ADR', 'non-existent')); + self::assertEquals('1@example.org', $vcard->getByType('EMAIL', 'home')->getValue()); + self::assertEquals('2@example.org', $vcard->getByType('EMAIL', 'work')->getValue()); + self::assertNull($vcard->getByType('EMAIL', 'non-existent')); + self::assertNull($vcard->getByType('ADR', 'non-existent')); } - public function testPreferredNoPref() + public function testPreferredNoPref(): void { $vcard = <<assertEquals('1@example.org', $vcard->preferred('EMAIL')->getValue()); + self::assertEquals('1@example.org', $vcard->preferred('EMAIL')->getValue()); } - public function testPreferredWithPref() + public function testPreferredWithPref(): void { $vcard = <<assertEquals('2@example.org', $vcard->preferred('EMAIL')->getValue()); + self::assertEquals('2@example.org', $vcard->preferred('EMAIL')->getValue()); } - public function testPreferredWith40Pref() + public function testPreferredWith40Pref(): void { $vcard = <<assertEquals('3@example.org', $vcard->preferred('EMAIL')->getValue()); + self::assertEquals('3@example.org', $vcard->preferred('EMAIL')->getValue()); } - public function testPreferredNotFound() + public function testPreferredNotFound(): void { $vcard = <<assertNull($vcard->preferred('EMAIL')); + self::assertNull($vcard->preferred('EMAIL')); } - public function testNoUIDCardDAV() + public function testNoUIDCardDAV(): void { $vcard = <<assertValidate( + self::assertValidate( $vcard, VCard::PROFILE_CARDDAV, 3, @@ -210,7 +218,7 @@ public function testNoUIDCardDAV() ); } - public function testNoUIDNoCardDAV() + public function testNoUIDNoCardDAV(): void { $vcard = <<assertValidate( + self::assertValidate( $vcard, 0, 2, @@ -226,7 +234,7 @@ public function testNoUIDNoCardDAV() ); } - public function testNoUIDNoCardDAVRepair() + public function testNoUIDNoCardDAVRepair(): void { $vcard = <<assertValidate( + self::assertValidate( $vcard, VCard::REPAIR, 1, @@ -242,7 +250,7 @@ public function testNoUIDNoCardDAVRepair() ); } - public function testVCard21CardDAV() + public function testVCard21CardDAV(): void { $vcard = <<assertValidate( + self::assertValidate( $vcard, VCard::PROFILE_CARDDAV, 3, @@ -259,7 +267,7 @@ public function testVCard21CardDAV() ); } - public function testVCard21NoCardDAV() + public function testVCard21NoCardDAV(): void { $vcard = <<assertValidate( + self::assertValidate( $vcard, 0, 0 ); } - public function assertValidate($vcf, $options, $expectedLevel, $expectedMessage = null) + public function assertValidate($vcf, $options, int $expectedLevel, string $expectedMessage = null): void { $vcal = VObject\Reader::read($vcf); $result = $vcal->validate($options); - $this->assertValidateResult($result, $expectedLevel, $expectedMessage); + self::assertValidateResult($result, $expectedLevel, $expectedMessage); } - public function assertValidateResult($input, $expectedLevel, $expectedMessage = null) + public function assertValidateResult($input, int $expectedLevel, string $expectedMessage = null): void { $messages = []; foreach ($input as $warning) { @@ -291,12 +299,12 @@ public function assertValidateResult($input, $expectedLevel, $expectedMessage = } if (0 === $expectedLevel) { - $this->assertEquals(0, count($input), 'No validation messages were expected. We got: '.implode(', ', $messages)); + self::assertCount(0, $input, 'No validation messages were expected. We got: '.implode(', ', $messages)); } else { - $this->assertEquals(1, count($input), 'We expected exactly 1 validation message, We got: '.implode(', ', $messages)); + self::assertCount(1, $input, 'We expected exactly 1 validation message, We got: '.implode(', ', $messages)); - $this->assertEquals($expectedMessage, $input[0]['message']); - $this->assertEquals($expectedLevel, $input[0]['level']); + self::assertEquals($expectedMessage, $input[0]['message']); + self::assertEquals($expectedLevel, $input[0]['level']); } } } diff --git a/tests/VObject/Component/VEventTest.php b/tests/VObject/Component/VEventTest.php index 635ae5acd..50fa626cc 100644 --- a/tests/VObject/Component/VEventTest.php +++ b/tests/VObject/Component/VEventTest.php @@ -9,12 +9,12 @@ class VEventTest extends TestCase /** * @dataProvider timeRangeTestData */ - public function testInTimeRange(VEvent $vevent, $start, $end, $outcome) + public function testInTimeRange(VEvent $vevent, \DateTime $start, \DateTime $end, bool $outcome): void { - $this->assertEquals($outcome, $vevent->isInTimeRange($start, $end)); + self::assertEquals($outcome, $vevent->isInTimeRange($start, $end)); } - public function timeRangeTestData() + public function timeRangeTestData(): array { $tests = []; @@ -42,9 +42,9 @@ public function timeRangeTestData() $tests[] = [$vevent4, new \DateTime('2011-01-01'), new \DateTime('2011-11-01'), false]; // Event with no end date should be treated as lasting the entire day. $tests[] = [$vevent4, new \DateTime('2011-12-25 16:00:00'), new \DateTime('2011-12-25 17:00:00'), true]; - // DTEND is non inclusive so all day events should not be returned on the next day. + // DTEND is non-inclusive so all day events should not be returned on the next day. $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00'), new \DateTime('2011-12-26 17:00:00'), false]; - // The timezone of timerange in question also needs to be considered. + // The timezone of time range in question also needs to be considered. $tests[] = [$vevent4, new \DateTime('2011-12-26 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2011-12-26 17:00:00', new \DateTimeZone('Europe/Berlin')), false]; $vevent5 = clone $vevent; @@ -70,7 +70,7 @@ public function timeRangeTestData() $vevent7->DTSTART['VALUE'] = 'DATE'; $vevent7->RRULE = 'FREQ=MONTHLY'; $tests[] = [$vevent7, new \DateTime('2012-02-01 15:00:00'), new \DateTime('2012-02-02'), true]; - // The timezone of timerange in question should also be considered. + // The timezone of time range in question should also be considered. $tests[] = [$vevent7, new \DateTime('2012-02-02 00:00:00', new \DateTimeZone('Europe/Berlin')), new \DateTime('2012-02-03 00:00:00', new \DateTimeZone('Europe/Berlin')), false]; // Added this test to check recurring events that have no instances. diff --git a/tests/VObject/Component/VFreeBusyTest.php b/tests/VObject/Component/VFreeBusyTest.php index 2aa4351ca..f3a521f95 100644 --- a/tests/VObject/Component/VFreeBusyTest.php +++ b/tests/VObject/Component/VFreeBusyTest.php @@ -8,7 +8,7 @@ class VFreeBusyTest extends TestCase { - public function testIsFree() + public function testIsFree(): void { $input = <<assertFalse($vfb->isFree(new \DateTime('2012-09-12 01:15:00', $tz), new \DateTime('2012-09-12 01:45:00', $tz))); - $this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 08:05:00', $tz), new \DateTime('2012-09-12 08:10:00', $tz))); - $this->assertFalse($vfb->isFree(new \DateTime('2012-09-12 10:15:00', $tz), new \DateTime('2012-09-12 10:45:00', $tz))); + self::assertFalse($vfb->isFree(new \DateTime('2012-09-12 01:15:00', $tz), new \DateTime('2012-09-12 01:45:00', $tz))); + self::assertFalse($vfb->isFree(new \DateTime('2012-09-12 08:05:00', $tz), new \DateTime('2012-09-12 08:10:00', $tz))); + self::assertFalse($vfb->isFree(new \DateTime('2012-09-12 10:15:00', $tz), new \DateTime('2012-09-12 10:45:00', $tz))); // Checking whether the end time is treated as non-inclusive - $this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:00:00', $tz), new \DateTime('2012-09-12 09:15:00', $tz))); - $this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:45:00', $tz), new \DateTime('2012-09-12 10:00:00', $tz))); - $this->assertTrue($vfb->isFree(new \DateTime('2012-09-12 11:00:00', $tz), new \DateTime('2012-09-12 12:00:00', $tz))); + self::assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:00:00', $tz), new \DateTime('2012-09-12 09:15:00', $tz))); + self::assertTrue($vfb->isFree(new \DateTime('2012-09-12 09:45:00', $tz), new \DateTime('2012-09-12 10:00:00', $tz))); + self::assertTrue($vfb->isFree(new \DateTime('2012-09-12 11:00:00', $tz), new \DateTime('2012-09-12 12:00:00', $tz))); } - public function testValidate() + public function testValidate(): void { $input = <<assertEquals([], $messages); + self::assertEquals([], $messages); } } diff --git a/tests/VObject/Component/VJournalTest.php b/tests/VObject/Component/VJournalTest.php index 67901b71b..98f478896 100644 --- a/tests/VObject/Component/VJournalTest.php +++ b/tests/VObject/Component/VJournalTest.php @@ -10,12 +10,12 @@ class VJournalTest extends TestCase /** * @dataProvider timeRangeTestData */ - public function testInTimeRange(VJournal $vtodo, $start, $end, $outcome) + public function testInTimeRange(VJournal $vtodo, \DateTime $start, \DateTime $end, bool $outcome): void { - $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); + self::assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); } - public function testValidate() + public function testValidate(): void { $input = <<assertEquals([], $messages); + self::assertEquals([], $messages); } - public function testValidateBroken() + public function testValidateBroken(): void { $input = <<assertEquals( + self::assertEquals( ['URL MUST NOT appear more than once in a VJOURNAL component'], $messages ); } - public function timeRangeTestData() + public function timeRangeTestData(): array { $calendar = new VCalendar(); diff --git a/tests/VObject/Component/VTimeZoneTest.php b/tests/VObject/Component/VTimeZoneTest.php index af9469d36..19a88cb74 100644 --- a/tests/VObject/Component/VTimeZoneTest.php +++ b/tests/VObject/Component/VTimeZoneTest.php @@ -7,7 +7,7 @@ class VTimeZoneTest extends TestCase { - public function testValidate() + public function testValidate(): void { $input = <<assertEquals([], $messages); + self::assertEquals([], $messages); } - public function testGetTimeZone() + public function testGetTimeZone(): void { $input = <<assertEquals( + self::assertEquals( $tz, $obj->VTIMEZONE->getTimeZone() ); diff --git a/tests/VObject/Component/VTodoTest.php b/tests/VObject/Component/VTodoTest.php index d5434458a..808675b36 100644 --- a/tests/VObject/Component/VTodoTest.php +++ b/tests/VObject/Component/VTodoTest.php @@ -10,12 +10,12 @@ class VTodoTest extends TestCase /** * @dataProvider timeRangeTestData */ - public function testInTimeRange(VTodo $vtodo, $start, $end, $outcome) + public function testInTimeRange(VTodo $vtodo, \DateTime $start, \DateTime $end, bool $outcome): void { - $this->assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); + self::assertEquals($outcome, $vtodo->isInTimeRange($start, $end)); } - public function timeRangeTestData() + public function timeRangeTestData(): array { $tests = []; @@ -64,7 +64,7 @@ public function timeRangeTestData() return $tests; } - public function testValidate() + public function testValidate(): void { $input = <<assertEquals([], $messages); + self::assertEquals([], $messages); } - public function testValidateInvalid() + public function testValidateInvalid(): void { $input = <<assertEquals([ + self::assertEquals([ 'UID MUST appear exactly once in a VTODO component', 'DTSTAMP MUST appear exactly once in a VTODO component', ], $messages); } - public function testValidateDUEDTSTARTMisMatch() + public function testValidateDueDateTimeStartMisMatch(): void { $input = <<assertEquals([ + self::assertEquals([ 'The value type (DATE or DATE-TIME) must be identical for DUE and DTSTART', ], $messages); } - public function testValidateDUEbeforeDTSTART() + public function testValidateDueBeforeDateTimeStart(): void { $input = <<assertEquals([ + self::assertEquals([ 'DUE must occur after DTSTART', ], $messages); } diff --git a/tests/VObject/ComponentTest.php b/tests/VObject/ComponentTest.php index cf3e196dc..4a247d906 100644 --- a/tests/VObject/ComponentTest.php +++ b/tests/VObject/ComponentTest.php @@ -8,7 +8,7 @@ class ComponentTest extends TestCase { - public function testIterate() + public function testIterate(): void { $comp = new VCalendar([], false); @@ -21,16 +21,16 @@ public function testIterate() $count = 0; foreach ($comp->children() as $key => $subcomponent) { ++$count; - $this->assertInstanceOf(Component::class, $subcomponent); + self::assertInstanceOf(Component::class, $subcomponent); if (2 === $count) { - $this->assertEquals(1, $key); + self::assertEquals(1, $key); } } - $this->assertEquals(2, $count); + self::assertEquals(2, $count); } - public function testMagicGet() + public function testMagicGet(): void { $comp = new VCalendar([], false); @@ -40,14 +40,17 @@ public function testMagicGet() $sub = $comp->createComponent('VTODO'); $comp->add($sub); - $event = $comp->vevent; - $this->assertInstanceOf(Component::class, $event); - $this->assertEquals('VEVENT', $event->name); + $event = $comp->VEVENT; + self::assertInstanceOf(Component::class, $event); + self::assertEquals('VEVENT', $event->name); - $this->assertNull($comp->vjournal); + self::assertNull($comp->VJOURNAL); } - public function testMagicGetGroups() + /** + * @throws InvalidDataException + */ + public function testMagicGetGroups(): void { $comp = new VCard(); @@ -60,19 +63,34 @@ public function testMagicGetGroups() $sub = $comp->createProperty('EMAIL', '3@3.com'); $comp->add($sub); - $emails = $comp->email; - $this->assertEquals(3, count($emails)); + $sub = $comp->createProperty('0.EMAIL', '0@0.com'); + $comp->add($sub); + + $emails = $comp->EMAIL; + self::assertCount(4, $emails); $email1 = $comp->{'group1.email'}; - $this->assertEquals('EMAIL', $email1[0]->name); - $this->assertEquals('GROUP1', $email1[0]->group); + self::assertEquals('EMAIL', $email1[0]->name); + self::assertEquals('GROUP1', $email1[0]->group); + + $email0 = $comp->{'0.email'}; + self::assertEquals('EMAIL', $email0[0]->name); + self::assertEquals('0', $email0[0]->group); + // this is supposed to return all EMAIL properties that do not have a group $email3 = $comp->{'.email'}; - $this->assertEquals('EMAIL', $email3[0]->name); - $this->assertEquals(null, $email3[0]->group); + self::assertEquals('EMAIL', $email3[0]->name); + self::assertEquals(null, $email3[0]->group); + + // this is supposed to return all properties that do not have a group + $nogroupProps = $comp->{'.'}; + self::assertGreaterThan(0, count($email3)); + foreach ($nogroupProps as $prop) { + self::assertEquals(null, $prop->group); + } } - public function testAddGroupProperties() + public function testAddGroupProperties(): void { $comp = new VCard([ 'VERSION' => '3.0', @@ -83,13 +101,13 @@ public function testAddGroupProperties() foreach (['item2', 'ITEM1'] as $group) { $prop = $comp->{"$group.X-ABLabel"}; - $this->assertInstanceOf(Property::class, $prop); - $this->assertSame("$group-Foo", (string) $prop); - $this->assertSame($group, $prop->group); + self::assertInstanceOf(Property::class, $prop); + self::assertSame("$group-Foo", (string) $prop); + self::assertSame($group, $prop->group); } } - public function testMagicIsset() + public function testMagicIsset(): void { $comp = new VCalendar(); @@ -99,65 +117,65 @@ public function testMagicIsset() $sub = $comp->createComponent('VTODO'); $comp->add($sub); - $this->assertTrue(isset($comp->vevent)); - $this->assertTrue(isset($comp->vtodo)); - $this->assertFalse(isset($comp->vjournal)); + self::assertTrue(isset($comp->vevent)); + self::assertTrue(isset($comp->vtodo)); + self::assertFalse(isset($comp->vjournal)); } - public function testMagicSetScalar() + public function testMagicSetScalar(): void { $comp = new VCalendar(); $comp->myProp = 'myValue'; - $this->assertInstanceOf(Property::class, $comp->MYPROP); - $this->assertEquals('myValue', (string) $comp->MYPROP); + self::assertInstanceOf(Property::class, $comp->MYPROP); + self::assertEquals('myValue', (string) $comp->MYPROP); } - public function testMagicSetScalarTwice() + public function testMagicSetScalarTwice(): void { $comp = new VCalendar([], false); $comp->myProp = 'myValue'; $comp->myProp = 'myValue'; - $this->assertEquals(1, count($comp->children())); - $this->assertInstanceOf(Property::class, $comp->MYPROP); - $this->assertEquals('myValue', (string) $comp->MYPROP); + self::assertCount(1, $comp->children()); + self::assertInstanceOf(Property::class, $comp->MYPROP); + self::assertEquals('myValue', (string) $comp->MYPROP); } - public function testMagicSetArray() + public function testMagicSetArray(): void { $comp = new VCalendar(); $comp->ORG = ['Acme Inc', 'Section 9']; - $this->assertInstanceOf(Property::class, $comp->ORG); - $this->assertEquals(['Acme Inc', 'Section 9'], $comp->ORG->getParts()); + self::assertInstanceOf(Property::class, $comp->ORG); + self::assertEquals(['Acme Inc', 'Section 9'], $comp->ORG->getParts()); } - public function testMagicSetComponent() + public function testMagicSetComponent(): void { $comp = new VCalendar(); // Note that 'myProp' is ignored here. $comp->myProp = $comp->createComponent('VEVENT'); - $this->assertEquals(1, count($comp)); + self::assertCount(1, $comp); - $this->assertEquals('VEVENT', $comp->VEVENT->name); + self::assertEquals('VEVENT', $comp->VEVENT->name); } - public function testMagicSetTwice() + public function testMagicSetTwice(): void { $comp = new VCalendar([], false); $comp->VEVENT = $comp->createComponent('VEVENT'); $comp->VEVENT = $comp->createComponent('VEVENT'); - $this->assertEquals(1, count($comp->children())); + self::assertCount(1, $comp->children()); - $this->assertEquals('VEVENT', $comp->VEVENT->name); + self::assertEquals('VEVENT', $comp->VEVENT->name); } - public function testArrayAccessGet() + public function testArrayAccessGet(): void { $comp = new VCalendar([], false); @@ -171,12 +189,12 @@ public function testArrayAccessGet() $comp->add($event2); - $this->assertEquals(2, count($comp->children())); - $this->assertTrue($comp->vevent[1] instanceof Component); - $this->assertEquals('Event 2', (string) $comp->vevent[1]->summary); + self::assertCount(2, $comp->children()); + self::assertTrue($comp->vevent[1] instanceof Component); + self::assertEquals('Event 2', (string) $comp->vevent[1]->summary); } - public function testArrayAccessExists() + public function testArrayAccessExists(): void { $comp = new VCalendar(); @@ -190,113 +208,113 @@ public function testArrayAccessExists() $comp->add($event2); - $this->assertTrue(isset($comp->vevent[0])); - $this->assertTrue(isset($comp->vevent[1])); + self::assertTrue(isset($comp->vevent[0])); + self::assertTrue(isset($comp->vevent[1])); } - public function testArrayAccessSet() + public function testArrayAccessSet(): void { $this->expectException(\LogicException::class); $comp = new VCalendar(); $comp['hey'] = 'hi there'; } - public function testArrayAccessUnset() + public function testArrayAccessUnset(): void { $this->expectException(\LogicException::class); $comp = new VCalendar(); unset($comp[0]); } - public function testAddScalar() + public function testAddScalar(): void { $comp = new VCalendar([], false); $comp->add('myprop', 'value'); - $this->assertEquals(1, count($comp->children())); + self::assertCount(1, $comp->children()); $bla = $comp->children()[0]; - $this->assertTrue($bla instanceof Property); - $this->assertEquals('MYPROP', $bla->name); - $this->assertEquals('value', (string) $bla); + self::assertTrue($bla instanceof Property); + self::assertEquals('MYPROP', $bla->name); + self::assertEquals('value', (string) $bla); } - public function testAddScalarParams() + public function testAddScalarParams(): void { $comp = new VCalendar([], false); $comp->add('myprop', 'value', ['param1' => 'value1']); - $this->assertEquals(1, count($comp->children())); + self::assertCount(1, $comp->children()); $bla = $comp->children()[0]; - $this->assertInstanceOf(Property::class, $bla); - $this->assertEquals('MYPROP', $bla->name); - $this->assertEquals('value', (string) $bla); + self::assertInstanceOf(Property::class, $bla); + self::assertEquals('MYPROP', $bla->name); + self::assertEquals('value', (string) $bla); - $this->assertEquals(1, count($bla->parameters())); + self::assertCount(1, $bla->parameters()); - $this->assertEquals('PARAM1', $bla->parameters['PARAM1']->name); - $this->assertEquals('value1', $bla->parameters['PARAM1']->getValue()); + self::assertEquals('PARAM1', $bla->parameters['PARAM1']->name); + self::assertEquals('value1', $bla->parameters['PARAM1']->getValue()); } - public function testAddComponent() + public function testAddComponent(): void { $comp = new VCalendar([], false); $comp->add($comp->createComponent('VEVENT')); - $this->assertEquals(1, count($comp->children())); + self::assertCount(1, $comp->children()); - $this->assertEquals('VEVENT', $comp->VEVENT->name); + self::assertEquals('VEVENT', $comp->VEVENT->name); } - public function testAddComponentTwice() + public function testAddComponentTwice(): void { $comp = new VCalendar([], false); $comp->add($comp->createComponent('VEVENT')); $comp->add($comp->createComponent('VEVENT')); - $this->assertEquals(2, count($comp->children())); + self::assertCount(2, $comp->children()); - $this->assertEquals('VEVENT', $comp->VEVENT->name); + self::assertEquals('VEVENT', $comp->VEVENT->name); } - public function testAddArgFail() + public function testAddArgFail(): void { $this->expectException(\InvalidArgumentException::class); $comp = new VCalendar(); $comp->add($comp->createComponent('VEVENT'), 'hello'); } - public function testAddArgFail2() + public function testAddArgFail2(): void { $this->expectException(\InvalidArgumentException::class); $comp = new VCalendar(); $comp->add([]); } - public function testMagicUnset() + public function testMagicUnset(): void { $comp = new VCalendar([], false); $comp->add($comp->createComponent('VEVENT')); unset($comp->vevent); - $this->assertEquals(0, count($comp->children())); + self::assertCount(0, $comp->children()); } - public function testCount() + public function testCount(): void { $comp = new VCalendar(); - $this->assertEquals(1, $comp->count()); + self::assertEquals(1, $comp->count()); } - public function testChildren() + public function testChildren(): void { $comp = new VCalendar([], false); @@ -305,11 +323,14 @@ public function testChildren() $comp->add($comp->createComponent('VTODO')); $r = $comp->children(); - $this->assertIsArray($r); - $this->assertEquals(2, count($r)); + self::assertIsArray($r); + self::assertCount(2, $r); } - public function testGetComponents() + /** + * @throws InvalidDataException + */ + public function testGetComponents(): void { $comp = new VCalendar(); @@ -317,18 +338,18 @@ public function testGetComponents() $comp->add($comp->createComponent('VTODO')); $r = $comp->getComponents(); - $this->assertIsArray($r); - $this->assertEquals(1, count($r)); - $this->assertEquals('VTODO', $r[0]->name); + self::assertIsArray($r); + self::assertCount(1, $r); + self::assertEquals('VTODO', $r[0]->name); } - public function testSerialize() + public function testSerialize(): void { $comp = new VCalendar([], false); - $this->assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $comp->serialize()); + self::assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $comp->serialize()); } - public function testSerializeChildren() + public function testSerializeChildren(): void { $comp = new VCalendar([], false); $event = $comp->add($comp->createComponent('VEVENT')); @@ -338,10 +359,10 @@ public function testSerializeChildren() $str = $comp->serialize(); - $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n", $str); + self::assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nBEGIN:VTODO\r\nEND:VTODO\r\nEND:VCALENDAR\r\n", $str); } - public function testSerializeOrderCompAndProp() + public function testSerializeOrderCompAndProp(): void { $comp = new VCalendar([], false); $comp->add($event = $comp->createComponent('VEVENT')); @@ -352,10 +373,10 @@ public function testSerializeOrderCompAndProp() unset($event->DTSTAMP, $event->UID); $str = $comp->serialize(); - $this->assertEquals("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPROP1:BLABLA\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $str); + self::assertEquals("BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPROP1:BLABLA\r\nBEGIN:VTIMEZONE\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $str); } - public function testAnotherSerializeOrderProp() + public function testAnotherSerializeOrderProp(): void { $prop4s = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']; @@ -378,21 +399,21 @@ public function testAnotherSerializeOrderProp() $str = $comp->serialize(); - $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.0\r\nSOMEPROP:FOO\r\nANOTHERPROP:FOO\r\nTHIRDPROP:FOO\r\nPROP4:FOO 1\r\nPROP4:FOO 2\r\nPROP4:FOO 3\r\nPROP4:FOO 4\r\nPROP4:FOO 5\r\nPROP4:FOO 6\r\nPROP4:FOO 7\r\nPROP4:FOO 8\r\nPROP4:FOO 9\r\nPROP4:FOO 10\r\nPROPNUMBERFIVE:FOO\r\nPROPNUMBERSIX:FOO\r\nPROPNUMBERSEVEN:FOO\r\nPROPNUMBEREIGHT:FOO\r\nPROPNUMBERNINE:FOO\r\nPROPNUMBERTEN:FOO\r\nUID:FOO\r\nEND:VCARD\r\n", $str); + self::assertEquals("BEGIN:VCARD\r\nVERSION:2.0\r\nSOMEPROP:FOO\r\nANOTHERPROP:FOO\r\nTHIRDPROP:FOO\r\nPROP4:FOO 1\r\nPROP4:FOO 2\r\nPROP4:FOO 3\r\nPROP4:FOO 4\r\nPROP4:FOO 5\r\nPROP4:FOO 6\r\nPROP4:FOO 7\r\nPROP4:FOO 8\r\nPROP4:FOO 9\r\nPROP4:FOO 10\r\nPROPNUMBERFIVE:FOO\r\nPROPNUMBERSIX:FOO\r\nPROPNUMBERSEVEN:FOO\r\nPROPNUMBEREIGHT:FOO\r\nPROPNUMBERNINE:FOO\r\nPROPNUMBERTEN:FOO\r\nUID:FOO\r\nEND:VCARD\r\n", $str); } - public function testInstantiateWithChildren() + public function testInstantiateWithChildren(): void { $comp = new VCard([ 'ORG' => ['Acme Inc.', 'Section 9'], 'FN' => 'Finn The Human', ]); - $this->assertEquals(['Acme Inc.', 'Section 9'], $comp->ORG->getParts()); - $this->assertEquals('Finn The Human', $comp->FN->getValue()); + self::assertEquals(['Acme Inc.', 'Section 9'], $comp->ORG->getParts()); + self::assertEquals('Finn The Human', $comp->FN->getValue()); } - public function testInstantiateSubComponent() + public function testInstantiateSubComponent(): void { $comp = new VCalendar(); $event = $comp->createComponent('VEVENT', [ @@ -400,10 +421,10 @@ public function testInstantiateSubComponent() ]); $comp->add($event); - $this->assertEquals('12345', $comp->VEVENT->UID->getValue()); + self::assertEquals('12345', $comp->VEVENT->UID->getValue()); } - public function testRemoveByName() + public function testRemoveByName(): void { $comp = new VCalendar([], false); $comp->add('prop1', 'val1'); @@ -411,22 +432,25 @@ public function testRemoveByName() $comp->add('prop2', 'val2'); $comp->remove('prop2'); - $this->assertFalse(isset($comp->prop2)); - $this->assertTrue(isset($comp->prop1)); + self::assertFalse(isset($comp->prop2)); + self::assertTrue(isset($comp->prop1)); } - public function testRemoveByObj() + public function testRemoveByObj(): void { $comp = new VCalendar([], false); $comp->add('prop1', 'val1'); $prop = $comp->add('prop2', 'val2'); $comp->remove($prop); - $this->assertFalse(isset($comp->prop2)); - $this->assertTrue(isset($comp->prop1)); + self::assertFalse(isset($comp->prop2)); + self::assertTrue(isset($comp->prop1)); } - public function testRemoveNotFound() + /** + * @throws InvalidDataException + */ + public function testRemoveNotFound(): void { $this->expectException(\InvalidArgumentException::class); $comp = new VCalendar([], false); @@ -437,28 +461,28 @@ public function testRemoveNotFound() /** * @dataProvider ruleData */ - public function testValidateRules($componentList, $errorCount) + public function testValidateRules(array $componentList, int $errorCount): void { $vcard = new Component\VCard(); - $component = new FakeComponent($vcard, 'Hi', [], $defaults = false); + $component = new FakeComponent($vcard, 'Hi', [], false); foreach ($componentList as $v) { $component->add($v, 'Hello.'); } - $this->assertEquals($errorCount, count($component->validate())); + self::assertCount($errorCount, $component->validate()); } - public function testValidateRepair() + public function testValidateRepair(): void { $vcard = new Component\VCard(); - $component = new FakeComponent($vcard, 'Hi', [], $defaults = false); + $component = new FakeComponent($vcard, 'Hi', [], false); $component->validate(Component::REPAIR); - $this->assertEquals('yow', $component->BAR->getValue()); + self::assertEquals('yow', $component->BAR->getValue()); } - public function testValidateRepairShouldNotDeduplicatePropertiesWhenValuesDiffer() + public function testValidateRepairShouldNotDeduplicatePropertiesWhenValuesDiffer(): void { $vcard = new Component\VCard(); @@ -469,12 +493,12 @@ public function testValidateRepairShouldNotDeduplicatePropertiesWhenValuesDiffer $messages = $component->validate(Component::REPAIR); - $this->assertEquals(1, count($messages)); - $this->assertEquals(3, $messages[0]['level']); - $this->assertEquals(2, count($component->GIR)); + self::assertCount(1, $messages); + self::assertEquals(3, $messages[0]['level']); + self::assertCount(2, $component->GIR); } - public function testValidateRepairShouldNotDeduplicatePropertiesWhenParametersDiffer() + public function testValidateRepairShouldNotDeduplicatePropertiesWhenParametersDiffer(): void { $vcard = new Component\VCard(); @@ -485,12 +509,12 @@ public function testValidateRepairShouldNotDeduplicatePropertiesWhenParametersDi $messages = $component->validate(Component::REPAIR); - $this->assertEquals(1, count($messages)); - $this->assertEquals(3, $messages[0]['level']); - $this->assertEquals(2, count($component->GIR)); + self::assertCount(1, $messages); + self::assertEquals(3, $messages[0]['level']); + self::assertCount(2, $component->GIR); } - public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAndParametersAreEqual() + public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAndParametersAreEqual(): void { $vcard = new Component\VCard(); @@ -501,12 +525,12 @@ public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAndParame $messages = $component->validate(Component::REPAIR); - $this->assertEquals(1, count($messages)); - $this->assertEquals(1, $messages[0]['level']); - $this->assertEquals(1, count($component->GIR)); + self::assertCount(1, $messages); + self::assertEquals(1, $messages[0]['level']); + self::assertCount(1, $component->GIR); } - public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAreEqual() + public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAreEqual(): void { $vcard = new Component\VCard(); @@ -517,12 +541,12 @@ public function testValidateRepairShouldDeduplicatePropertiesWhenValuesAreEqual( $messages = $component->validate(Component::REPAIR); - $this->assertEquals(1, count($messages)); - $this->assertEquals(1, $messages[0]['level']); - $this->assertEquals(1, count($component->GIR)); + self::assertCount(1, $messages); + self::assertEquals(1, $messages[0]['level']); + self::assertCount(1, $component->GIR); } - public function ruleData() + public function ruleData(): array { return [ [[], 2], @@ -539,7 +563,7 @@ public function ruleData() class FakeComponent extends Component { - public function getValidationRules() + public function getValidationRules(): array { return [ 'FOO' => '0', @@ -550,7 +574,7 @@ public function getValidationRules() ]; } - public function getDefaults() + public function getDefaults(): array { return [ 'BAR' => 'yow', diff --git a/tests/VObject/DateTimeParserTest.php b/tests/VObject/DateTimeParserTest.php index ede81e321..cdf0fe990 100644 --- a/tests/VObject/DateTimeParserTest.php +++ b/tests/VObject/DateTimeParserTest.php @@ -2,185 +2,194 @@ namespace Sabre\VObject; -use DateInterval; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; class DateTimeParserTest extends TestCase { - public function testParseICalendarDuration() + /** + * @throws InvalidDataException + */ + public function testParseICalendarDuration(): void { - $this->assertEquals('+1 weeks', DateTimeParser::parseDuration('P1W', true)); - $this->assertEquals('+5 days', DateTimeParser::parseDuration('P5D', true)); - $this->assertEquals('+5 days 3 hours 50 minutes 12 seconds', DateTimeParser::parseDuration('P5DT3H50M12S', true)); - $this->assertEquals('-1 weeks 50 minutes', DateTimeParser::parseDuration('-P1WT50M', true)); - $this->assertEquals('+50 days 3 hours 2 seconds', DateTimeParser::parseDuration('+P50DT3H2S', true)); - $this->assertEquals('+0 seconds', DateTimeParser::parseDuration('+PT0S', true)); - $this->assertEquals(new DateInterval('PT0S'), DateTimeParser::parseDuration('PT0S')); + self::assertEquals('+1 weeks', DateTimeParser::parseDurationAsString('P1W')); + self::assertEquals('+5 days', DateTimeParser::parseDurationAsString('P5D')); + self::assertEquals('+5 days 3 hours 50 minutes 12 seconds', DateTimeParser::parseDurationAsString('P5DT3H50M12S')); + self::assertEquals('-1 weeks 50 minutes', DateTimeParser::parseDurationAsString('-P1WT50M')); + self::assertEquals('+50 days 3 hours 2 seconds', DateTimeParser::parseDurationAsString('+P50DT3H2S')); + self::assertEquals('+0 seconds', DateTimeParser::parseDurationAsString('+PT0S')); + self::assertEquals(new \DateInterval('PT0S'), DateTimeParser::parseDuration('PT0S')); } - public function testParseICalendarDurationDateInterval() + /** + * @throws InvalidDataException + */ + public function testParseICalendarDurationDateInterval(): void { - $expected = new DateInterval('P7D'); - $this->assertEquals($expected, DateTimeParser::parseDuration('P1W')); - $this->assertEquals($expected, DateTimeParser::parse('P1W')); + $expected = new \DateInterval('P7D'); + self::assertEquals($expected, DateTimeParser::parseDuration('P1W')); + self::assertEquals($expected, DateTimeParser::parse('P1W')); - $expected = new DateInterval('PT3M'); + $expected = new \DateInterval('PT3M'); $expected->invert = true; - $this->assertEquals($expected, DateTimeParser::parseDuration('-PT3M')); + self::assertEquals($expected, DateTimeParser::parseDuration('-PT3M')); + } + + public function testParseDurationZero(): void + { + $expected = new \DateInterval('PT0S'); + self::assertEquals($expected, DateTimeParser::parseDuration('P')); } - public function testParseICalendarDurationFail() + public function testParseICalendarDurationFail(): void { $this->expectException(InvalidDataException::class); - DateTimeParser::parseDuration('P1X', true); + DateTimeParser::parseDurationAsString('P1X'); } - public function testParseICalendarDateTime() + public function testParseICalendarDateTime(): void { $dateTime = DateTimeParser::parseDateTime('20100316T141405'); - $compare = new DateTimeImmutable('2010-03-16 14:14:05', new DateTimeZone('UTC')); + $compare = new \DateTimeImmutable('2010-03-16 14:14:05', new \DateTimeZone('UTC')); - $this->assertEquals($compare, $dateTime); + self::assertEquals($compare, $dateTime); } /** * @depends testParseICalendarDateTime */ - public function testParseICalendarDateTimeBadFormat() + public function testParseICalendarDateTimeBadFormat(): void { $this->expectException(InvalidDataException::class); - $dateTime = DateTimeParser::parseDateTime('20100316T141405 '); + DateTimeParser::parseDateTime('20100316T141405 '); } /** * @depends testParseICalendarDateTime */ - public function testParseICalendarDateTimeInvalidTime() + public function testParseICalendarDateTimeInvalidTime(): void { $this->expectException(InvalidDataException::class); - $dateTime = DateTimeParser::parseDateTime('20100316T251405'); + DateTimeParser::parseDateTime('20100316T251405'); } /** * @depends testParseICalendarDateTime */ - public function testParseICalendarDateTimeUTC() + public function testParseICalendarDateTimeUTC(): void { $dateTime = DateTimeParser::parseDateTime('20100316T141405Z'); - $compare = new DateTimeImmutable('2010-03-16 14:14:05', new DateTimeZone('UTC')); - $this->assertEquals($compare, $dateTime); + $compare = new \DateTimeImmutable('2010-03-16 14:14:05', new \DateTimeZone('UTC')); + self::assertEquals($compare, $dateTime); } /** * @depends testParseICalendarDateTime */ - public function testParseICalendarDateTimeUTC2() + public function testParseICalendarDateTimeUTC2(): void { $dateTime = DateTimeParser::parseDateTime('20101211T160000Z'); - $compare = new DateTimeImmutable('2010-12-11 16:00:00', new DateTimeZone('UTC')); - $this->assertEquals($compare, $dateTime); + $compare = new \DateTimeImmutable('2010-12-11 16:00:00', new \DateTimeZone('UTC')); + self::assertEquals($compare, $dateTime); } /** * @depends testParseICalendarDateTime */ - public function testParseICalendarDateTimeCustomTimeZone() + public function testParseICalendarDateTimeCustomTimeZone(): void { - $dateTime = DateTimeParser::parseDateTime('20100316T141405', new DateTimeZone('Europe/Amsterdam')); + $dateTime = DateTimeParser::parseDateTime('20100316T141405', new \DateTimeZone('Europe/Amsterdam')); - $compare = new DateTimeImmutable('2010-03-16 14:14:05', new DateTimeZone('Europe/Amsterdam')); - $this->assertEquals($compare, $dateTime); + $compare = new \DateTimeImmutable('2010-03-16 14:14:05', new \DateTimeZone('Europe/Amsterdam')); + self::assertEquals($compare, $dateTime); } - public function testParseICalendarDate() + public function testParseICalendarDate(): void { $dateTime = DateTimeParser::parseDate('20100316'); - $expected = new DateTimeImmutable('2010-03-16 00:00:00', new DateTimeZone('UTC')); + $expected = new \DateTimeImmutable('2010-03-16 00:00:00', new \DateTimeZone('UTC')); - $this->assertEquals($expected, $dateTime); + self::assertEquals($expected, $dateTime); $dateTime = DateTimeParser::parse('20100316'); - $this->assertEquals($expected, $dateTime); + self::assertEquals($expected, $dateTime); } /** * TCheck if a date with year > 4000 will not throw an exception. iOS seems to use 45001231 in yearly recurring events. */ - public function testParseICalendarDateGreaterThan4000() + public function testParseICalendarDateGreaterThan4000(): void { $dateTime = DateTimeParser::parseDate('45001231'); - $expected = new DateTimeImmutable('4500-12-31 00:00:00', new DateTimeZone('UTC')); + $expected = new \DateTimeImmutable('4500-12-31 00:00:00', new \DateTimeZone('UTC')); - $this->assertEquals($expected, $dateTime); + self::assertEquals($expected, $dateTime); $dateTime = DateTimeParser::parse('45001231'); - $this->assertEquals($expected, $dateTime); + self::assertEquals($expected, $dateTime); } /** * Check if a datetime with year > 4000 will not throw an exception. iOS seems to use 45001231T235959 in yearly recurring events. */ - public function testParseICalendarDateTimeGreaterThan4000() + public function testParseICalendarDateTimeGreaterThan4000(): void { $dateTime = DateTimeParser::parseDateTime('45001231T235959'); - $expected = new DateTimeImmutable('4500-12-31 23:59:59', new DateTimeZone('UTC')); + $expected = new \DateTimeImmutable('4500-12-31 23:59:59', new \DateTimeZone('UTC')); - $this->assertEquals($expected, $dateTime); + self::assertEquals($expected, $dateTime); $dateTime = DateTimeParser::parse('45001231T235959'); - $this->assertEquals($expected, $dateTime); + self::assertEquals($expected, $dateTime); } /** * @depends testParseICalendarDate */ - public function testParseICalendarDateBadFormat() + public function testParseICalendarDateBadFormat(): void { $this->expectException(InvalidDataException::class); - $dateTime = DateTimeParser::parseDate('20100316T141405'); + DateTimeParser::parseDate('20100316T141405'); } /** * @depends testParseICalendarDate */ - public function testParseICalendarDateInvalidDate() + public function testParseICalendarDateInvalidDate(): void { $this->expectException(InvalidDataException::class); - $dateTime = DateTimeParser::parseDate('20101331'); + DateTimeParser::parseDate('20101331'); } /** * @dataProvider vcardDates */ - public function testVCardDate($input, $output) + public function testVCardDate(string $input, array $output): void { - $this->assertEquals( + self::assertEquals( $output, DateTimeParser::parseVCardDateTime($input) ); } - public function testBadVCardDate() + public function testBadVCardDate(): void { $this->expectException(InvalidDataException::class); DateTimeParser::parseVCardDateTime('1985---01'); } - public function testBadVCardTime() + public function testBadVCardTime(): void { $this->expectException(InvalidDataException::class); DateTimeParser::parseVCardTime('23:12:166'); } - public function vcardDates() + public function vcardDates(): array { return [ [ @@ -408,9 +417,9 @@ public function vcardDates() ]; } - public function testDateAndOrTimeDateWithYearMonthDay() + public function testDateAndOrTimeDateWithYearMonthDay(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '20150128', [ 'year' => '2015', @@ -420,9 +429,9 @@ public function testDateAndOrTimeDateWithYearMonthDay() ); } - public function testDateAndOrTimeDateWithYearMonth() + public function testDateAndOrTimeDateWithYearMonth(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '2015-01', [ 'year' => '2015', @@ -431,9 +440,9 @@ public function testDateAndOrTimeDateWithYearMonth() ); } - public function testDateAndOrTimeDateWithMonth() + public function testDateAndOrTimeDateWithMonth(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '--01', [ 'month' => '01', @@ -441,9 +450,9 @@ public function testDateAndOrTimeDateWithMonth() ); } - public function testDateAndOrTimeDateWithMonthDay() + public function testDateAndOrTimeDateWithMonthDay(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '--0128', [ 'month' => '01', @@ -452,9 +461,9 @@ public function testDateAndOrTimeDateWithMonthDay() ); } - public function testDateAndOrTimeDateWithDay() + public function testDateAndOrTimeDateWithDay(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '---28', [ 'date' => '28', @@ -462,9 +471,9 @@ public function testDateAndOrTimeDateWithDay() ); } - public function testDateAndOrTimeTimeWithHour() + public function testDateAndOrTimeTimeWithHour(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '13', [ 'hour' => '13', @@ -472,9 +481,9 @@ public function testDateAndOrTimeTimeWithHour() ); } - public function testDateAndOrTimeTimeWithHourMinute() + public function testDateAndOrTimeTimeWithHourMinute(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '1353', [ 'hour' => '13', @@ -483,9 +492,9 @@ public function testDateAndOrTimeTimeWithHourMinute() ); } - public function testDateAndOrTimeTimeWithHourSecond() + public function testDateAndOrTimeTimeWithHourSecond(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '135301', [ 'hour' => '13', @@ -495,9 +504,9 @@ public function testDateAndOrTimeTimeWithHourSecond() ); } - public function testDateAndOrTimeTimeWithMinute() + public function testDateAndOrTimeTimeWithMinute(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '-53', [ 'minute' => '53', @@ -505,9 +514,9 @@ public function testDateAndOrTimeTimeWithMinute() ); } - public function testDateAndOrTimeTimeWithMinuteSecond() + public function testDateAndOrTimeTimeWithMinuteSecond(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '-5301', [ 'minute' => '53', @@ -516,9 +525,9 @@ public function testDateAndOrTimeTimeWithMinuteSecond() ); } - public function testDateAndOrTimeTimeWithSecond() + public function testDateAndOrTimeTimeWithSecond(): void { - $this->assertTrue(true); + self::assertTrue(true); /* * This is unreachable due to a conflict between date and time pattern. @@ -526,9 +535,9 @@ public function testDateAndOrTimeTimeWithSecond() */ } - public function testDateAndOrTimeTimeWithSecondZ() + public function testDateAndOrTimeTimeWithSecondZ(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '--01Z', [ 'second' => '01', @@ -537,9 +546,9 @@ public function testDateAndOrTimeTimeWithSecondZ() ); } - public function testDateAndOrTimeTimeWithSecondTZ() + public function testDateAndOrTimeTimeWithSecondTZ(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '--01+1234', [ 'second' => '01', @@ -548,9 +557,9 @@ public function testDateAndOrTimeTimeWithSecondTZ() ); } - public function testDateAndOrTimeDateTimeWithYearMonthDayHour() + public function testDateAndOrTimeDateTimeWithYearMonthDayHour(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '20150128T13', [ 'year' => '2015', @@ -561,9 +570,9 @@ public function testDateAndOrTimeDateTimeWithYearMonthDayHour() ); } - public function testDateAndOrTimeDateTimeWithMonthDayHour() + public function testDateAndOrTimeDateTimeWithMonthDayHour(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '--0128T13', [ 'month' => '01', @@ -573,9 +582,9 @@ public function testDateAndOrTimeDateTimeWithMonthDayHour() ); } - public function testDateAndOrTimeDateTimeWithDayHour() + public function testDateAndOrTimeDateTimeWithDayHour(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '---28T13', [ 'date' => '28', @@ -584,9 +593,9 @@ public function testDateAndOrTimeDateTimeWithDayHour() ); } - public function testDateAndOrTimeDateTimeWithDayHourMinute() + public function testDateAndOrTimeDateTimeWithDayHourMinute(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '---28T1353', [ 'date' => '28', @@ -596,9 +605,9 @@ public function testDateAndOrTimeDateTimeWithDayHourMinute() ); } - public function testDateAndOrTimeDateTimeWithDayHourMinuteSecond() + public function testDateAndOrTimeDateTimeWithDayHourMinuteSecond(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '---28T135301', [ 'date' => '28', @@ -609,9 +618,9 @@ public function testDateAndOrTimeDateTimeWithDayHourMinuteSecond() ); } - public function testDateAndOrTimeDateTimeWithDayHourZ() + public function testDateAndOrTimeDateTimeWithDayHourZ(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '---28T13Z', [ 'date' => '28', @@ -621,9 +630,9 @@ public function testDateAndOrTimeDateTimeWithDayHourZ() ); } - public function testDateAndOrTimeDateTimeWithDayHourTZ() + public function testDateAndOrTimeDateTimeWithDayHourTZ(): void { - $this->assertDateAndOrTimeEqualsTo( + self::assertDateAndOrTimeEqualsTo( '---28T13+1234', [ 'date' => '28', @@ -633,9 +642,9 @@ public function testDateAndOrTimeDateTimeWithDayHourTZ() ); } - protected function assertDateAndOrTimeEqualsTo($date, $parts) + protected function assertDateAndOrTimeEqualsTo(string $date, array $parts): void { - $this->assertSame( + self::assertSame( DateTimeParser::parseVCardDateAndOrTime($date), array_merge( [ diff --git a/tests/VObject/DocumentTest.php b/tests/VObject/DocumentTest.php index f2698f65f..d03a88836 100644 --- a/tests/VObject/DocumentTest.php +++ b/tests/VObject/DocumentTest.php @@ -6,29 +6,29 @@ class DocumentTest extends TestCase { - public function testGetDocumentType() + public function testGetDocumentType(): void { - $doc = new MockDocument(); - $this->assertEquals(Document::UNKNOWN, $doc->getDocumentType()); + $doc = new MockDocument('WHATEVER'); + self::assertEquals(Document::UNKNOWN, $doc->getDocumentType()); } - public function testConstruct() + public function testConstruct(): void { $doc = new MockDocument('VLIST'); - $this->assertEquals('VLIST', $doc->name); + self::assertEquals('VLIST', $doc->name); } - public function testCreateComponent() + public function testCreateComponent(): void { $vcal = new Component\VCalendar([], false); $event = $vcal->createComponent('VEVENT'); - $this->assertInstanceOf(Component\VEvent::class, $event); + self::assertInstanceOf(Component\VEvent::class, $event); $vcal->add($event); $prop = $vcal->createProperty('X-PROP', '1234256', ['X-PARAM' => '3']); - $this->assertInstanceOf(Property::class, $prop); + self::assertInstanceOf(Property::class, $prop); $event->add($prop); @@ -38,44 +38,47 @@ public function testCreateComponent() ); $out = $vcal->serialize(); - $this->assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nX-PROP;X-PARAM=3:1234256\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $out); + self::assertEquals("BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nX-PROP;X-PARAM=3:1234256\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n", $out); } - public function testCreate() + public function testCreate(): void { $vcal = new Component\VCalendar([], false); $event = $vcal->create('VEVENT'); - $this->assertInstanceOf(Component\VEvent::class, $event); + self::assertInstanceOf(Component\VEvent::class, $event); $prop = $vcal->create('CALSCALE'); - $this->assertInstanceOf(Property\Text::class, $prop); + self::assertInstanceOf(Property\Text::class, $prop); } - public function testGetClassNameForPropertyValue() + public function testGetClassNameForPropertyValue(): void { $vcal = new Component\VCalendar([], false); - $this->assertEquals(Property\Text::class, $vcal->getClassNameForPropertyValue('TEXT')); - $this->assertNull($vcal->getClassNameForPropertyValue('FOO')); + self::assertEquals(Property\Text::class, $vcal->getClassNameForPropertyValue('TEXT')); + self::assertNull($vcal->getClassNameForPropertyValue('FOO')); } - public function testDestroy() + /** + * @throws InvalidDataException + */ + public function testDestroy(): void { $vcal = new Component\VCalendar([], false); $event = $vcal->createComponent('VEVENT'); - $this->assertInstanceOf(Component\VEvent::class, $event); + self::assertInstanceOf(Component\VEvent::class, $event); $vcal->add($event); $prop = $vcal->createProperty('X-PROP', '1234256', ['X-PARAM' => '3']); $event->add($prop); - $this->assertEquals($event, $prop->parent); + self::assertEquals($event, $prop->parent); $vcal->destroy(); - $this->assertNull($prop->parent); + self::assertNull($prop->parent); } } diff --git a/tests/VObject/ElementListTest.php b/tests/VObject/ElementListTest.php index f3bb8f2bb..22b616fb9 100644 --- a/tests/VObject/ElementListTest.php +++ b/tests/VObject/ElementListTest.php @@ -6,7 +6,7 @@ class ElementListTest extends TestCase { - public function testIterate() + public function testIterate(): void { $cal = new Component\VCalendar(); $sub = $cal->createComponent('VEVENT'); @@ -22,12 +22,12 @@ public function testIterate() $count = 0; foreach ($elemList as $key => $subcomponent) { ++$count; - $this->assertInstanceOf(Component::class, $subcomponent); + self::assertInstanceOf(Component::class, $subcomponent); if (3 === $count) { - $this->assertEquals(2, $key); + self::assertEquals(2, $key); } } - $this->assertEquals(3, $count); + self::assertEquals(3, $count); } } diff --git a/tests/VObject/EmClientTest.php b/tests/VObject/EmClientTest.php index bb586ba97..0af6fdb2f 100644 --- a/tests/VObject/EmClientTest.php +++ b/tests/VObject/EmClientTest.php @@ -2,12 +2,11 @@ namespace Sabre\VObject; -use DateTimeImmutable; use PHPUnit\Framework\TestCase; class EmClientTest extends TestCase { - public function testParseTz() + public function testParseTz(): void { $str = 'BEGIN:VCALENDAR X-WR-CALNAME:Blackhawks Schedule 2011-12 @@ -50,6 +49,6 @@ public function testParseTz() $vObject = Reader::read($str); $dt = $vObject->VEVENT->DTSTART->getDateTime(); - $this->assertEquals(new DateTimeImmutable('2011-10-08 19:30:00', new \DateTimeZone('America/Chicago')), $dt); + self::assertEquals(new \DateTimeImmutable('2011-10-08 19:30:00', new \DateTimeZone('America/Chicago')), $dt); } } diff --git a/tests/VObject/EmptyParameterTest.php b/tests/VObject/EmptyParameterTest.php index 52fe878e2..6739f104a 100644 --- a/tests/VObject/EmptyParameterTest.php +++ b/tests/VObject/EmptyParameterTest.php @@ -6,7 +6,7 @@ class EmptyParameterTest extends TestCase { - public function testRead() + public function testRead(): void { $input = <<assertInstanceOf(Component\VCard::class, $vcard); - $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30); + self::assertInstanceOf(Component\VCard::class, $vcard); + $vcard = $vcard->convert(Document::VCARD30); $vcard = $vcard->serialize(); $converted = Reader::read($vcard); $converted->validate(); - $this->assertTrue(isset($converted->EMAIL['X-INTERN'])); + self::assertTrue(isset($converted->EMAIL['X-INTERN'])); $version = Version::VERSION; @@ -43,10 +43,10 @@ public function testRead() VCF; - $this->assertEquals($expected, str_replace("\r", '', $vcard)); + self::assertEquals($expected, str_replace("\r", '', $vcard)); } - public function testVCard21Parameter() + public function testVCard21Parameter(): void { $vcard = new Component\VCard([], false); $vcard->VERSION = '2.1'; @@ -64,6 +64,6 @@ public function testVCard21Parameter() '', ]; - $this->assertEquals(implode("\r\n", $expected), $result); + self::assertEquals(implode("\r\n", $expected), $result); } } diff --git a/tests/VObject/EmptyValueIssueTest.php b/tests/VObject/EmptyValueIssueTest.php index 0798d9c4a..533ac6ab6 100644 --- a/tests/VObject/EmptyValueIssueTest.php +++ b/tests/VObject/EmptyValueIssueTest.php @@ -11,7 +11,7 @@ */ class EmptyValueIssueTest extends TestCase { - public function testDecodeValue() + public function testDecodeValue(): void { $input = <<assertEquals("This is a description\nwith a linebreak and a ; , and :", $vobj->VEVENT->DESCRIPTION->getValue()); + self::assertEquals("This is a description\nwith a linebreak and a ; , and :", $vobj->VEVENT->DESCRIPTION->getValue()); } } diff --git a/tests/VObject/FreeBusyDataTest.php b/tests/VObject/FreeBusyDataTest.php index 9e5143f65..10b2f403f 100644 --- a/tests/VObject/FreeBusyDataTest.php +++ b/tests/VObject/FreeBusyDataTest.php @@ -6,11 +6,11 @@ class FreeBusyDataTest extends TestCase { - public function testGetData() + public function testGetData(): void { $fb = new FreeBusyData(100, 200); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -25,14 +25,14 @@ public function testGetData() /** * @depends testGetData */ - public function testAddBeginning() + public function testAddBeginning(): void { $fb = new FreeBusyData(100, 200); // Overwriting the first half $fb->add(100, 150, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -51,7 +51,7 @@ public function testAddBeginning() // Overwriting the first half again $fb->add(100, 150, 'BUSY-TENTATIVE'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -71,14 +71,14 @@ public function testAddBeginning() /** * @depends testAddBeginning */ - public function testAddEnd() + public function testAddEnd(): void { $fb = new FreeBusyData(100, 200); // Overwriting the first half $fb->add(150, 200, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -98,14 +98,14 @@ public function testAddEnd() /** * @depends testAddEnd */ - public function testAddMiddle() + public function testAddMiddle(): void { $fb = new FreeBusyData(100, 200); // Overwriting the first half $fb->add(150, 160, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -130,14 +130,14 @@ public function testAddMiddle() /** * @depends testAddMiddle */ - public function testAddMultiple() + public function testAddMultiple(): void { $fb = new FreeBusyData(100, 200); $fb->add(110, 120, 'BUSY'); $fb->add(130, 140, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -172,14 +172,14 @@ public function testAddMultiple() /** * @depends testAddMultiple */ - public function testAddMultipleOverlap() + public function testAddMultipleOverlap(): void { $fb = new FreeBusyData(100, 200); $fb->add(110, 120, 'BUSY'); $fb->add(130, 140, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -212,7 +212,7 @@ public function testAddMultipleOverlap() $fb->add(115, 135, 'BUSY-TENTATIVE'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -247,14 +247,14 @@ public function testAddMultipleOverlap() /** * @depends testAddMultipleOverlap */ - public function testAddMultipleOverlapAndMerge() + public function testAddMultipleOverlapAndMerge(): void { $fb = new FreeBusyData(100, 200); $fb->add(110, 120, 'BUSY'); $fb->add(130, 140, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, @@ -287,7 +287,7 @@ public function testAddMultipleOverlapAndMerge() $fb->add(115, 135, 'BUSY'); - $this->assertEquals( + self::assertEquals( [ [ 'start' => 100, diff --git a/tests/VObject/FreeBusyGeneratorTest.php b/tests/VObject/FreeBusyGeneratorTest.php index 4700a2800..47283eafb 100644 --- a/tests/VObject/FreeBusyGeneratorTest.php +++ b/tests/VObject/FreeBusyGeneratorTest.php @@ -8,7 +8,7 @@ class FreeBusyGeneratorTest extends TestCase { use PHPUnitAssertions; - public function testGeneratorBaseObject() + public function testGeneratorBaseObject(): void { $obj = new Component\VCalendar(); $obj->METHOD = 'PUBLISH'; @@ -19,13 +19,13 @@ public function testGeneratorBaseObject() $result = $gen->getResult(); - $this->assertEquals('PUBLISH', $result->METHOD->getValue()); + self::assertEquals('PUBLISH', $result->METHOD->getValue()); } - public function testInvalidArg() + public function testInvalidArg(): void { $this->expectException(\InvalidArgumentException::class); - $gen = new FreeBusyGenerator( + new FreeBusyGenerator( new \DateTime('2012-01-01'), new \DateTime('2012-12-31'), new \stdClass() @@ -42,12 +42,11 @@ public function testInvalidArg() * It only generates the freebusy report for the following time-range: * 2011-01-01 11:00:00 until 2011-01-03 11:11:11 * - * @param string $expected - * @param array $input - * @param string|null $timeZone - * @param string $vavailability + * @param array|string $input + * + * @throws ParseException */ - public function assertFreeBusyReport($expected, $input, $timeZone = null, $vavailability = null) + public function assertFreeBusyReport(string $expected, $input, \DateTimeZone $timeZone = null, string $vavailability = null): void { $gen = new FreeBusyGenerator( new \DateTime('20110101T110000Z', new \DateTimeZone('UTC')), @@ -79,10 +78,10 @@ public function assertFreeBusyReport($expected, $input, $timeZone = null, $vavai END:VCALENDAR ICS; - $this->assertVObjectEqualsVObject($expected, $output); + self::assertVObjectEqualsVObject($expected, $output); } - public function testSimple() + public function testSimple(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $blob ); } - public function testSource() + public function testSource(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $h ); @@ -124,7 +123,7 @@ public function testSource() /** * Testing TRANSP:OPAQUE. */ - public function testOpaque() + public function testOpaque(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T130000Z/20110101T140000Z', $blob ); @@ -146,7 +145,7 @@ public function testOpaque() /** * Testing TRANSP:TRANSPARENT. */ - public function testTransparent() + public function testTransparent(): void { // transparent, hidden $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( '', $blob ); @@ -169,7 +168,7 @@ public function testTransparent() /** * Testing STATUS:CANCELLED. */ - public function testCancelled() + public function testCancelled(): void { // transparent, hidden $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( '', $blob ); @@ -192,7 +191,7 @@ public function testCancelled() /** * Testing STATUS:TENTATIVE. */ - public function testTentative() + public function testTentative(): void { // tentative, shows up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T180000Z/20110101T190000Z', $blob ); } /** - * Testing an event that falls outside of the report time-range. + * Testing an event that falls outside the report time-range. */ - public function testOutsideTimeRange() + public function testOutsideTimeRange(): void { - // outside of time-range, hidden + // outside time-range, hidden $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( '', $blob ); } /** - * Testing an event that falls outside of the report time-range. + * Testing an event that falls outside the report time-range. */ - public function testOutsideTimeRange2() + public function testOutsideTimeRange2(): void { - // outside of time-range, hidden + // outside time-range, hidden $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( '', $blob ); @@ -259,7 +258,7 @@ public function testOutsideTimeRange2() /** * Testing an event that uses DURATION. */ - public function testDuration() + public function testDuration(): void { // using duration, shows up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T190000Z/20110101T200000Z', $blob ); @@ -281,7 +280,7 @@ public function testDuration() /** * Testing an all-day event. */ - public function testAllDay() + public function testAllDay(): void { // Day-long event, shows up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110102T000000Z/20110103T000000Z', $blob ); @@ -302,7 +301,7 @@ public function testAllDay() /** * Testing an event that has no end or duration. */ - public function testNoDuration() + public function testNoDuration(): void { // No duration, does not show up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( '', $blob ); @@ -323,7 +322,7 @@ public function testNoDuration() /** * Testing feeding the freebusy generator an object instead of a string. */ - public function testObject() + public function testObject(): void { // encoded as object, shows up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T210000Z/20110101T220000Z', Reader::read($blob) ); @@ -345,7 +344,7 @@ public function testObject() /** * Testing feeding VFREEBUSY objects instead of VEVENT. */ - public function testVFreeBusy() + public function testVFreeBusy(): void { // Freebusy. Some parts show up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( "FREEBUSY:20110103T010000Z/20110103T020000Z\n". 'FREEBUSY:20110103T030000Z/20110103T060000Z', $blob ); } - public function testYearlyRecurrence() + public function testYearlyRecurrence(): void { // Yearly recurrence rule, shows up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T220000Z/20110101T230000Z', $blob ); } - public function testYearlyRecurrenceDuration() + public function testYearlyRecurrenceDuration(): void { // Yearly recurrence rule + duration, shows up $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T230000Z/20110102T000000Z', $blob ); } - public function testFloatingTime() + public function testFloatingTime(): void { // Floating time, no timezone $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $blob ); } - public function testFloatingTimeReferenceTimeZone() + public function testFloatingTimeReferenceTimeZone(): void { // Floating time + reference timezone $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T170000Z/20110101T180000Z', $blob, new \DateTimeZone('America/Toronto') ); } - public function testAllDay2() + public function testAllDay2(): void { - // All-day event, slightly outside of the VFREEBUSY range. + // All-day event, slightly outside the VFREEBUSY range. $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T110000Z/20110102T000000Z', $blob ); } - public function testAllDayReferenceTimeZone() + public function testAllDayReferenceTimeZone(): void { // All-day event + reference timezone $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T110000Z/20110102T050000Z', $blob, new \DateTimeZone('America/Toronto') ); } - public function testNoValidInstances() + public function testNoValidInstances(): void { // Recurrence rule with no valid instances $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( '', $blob ); @@ -508,7 +507,7 @@ public function testNoValidInstances() * This VAVAILABILITY object overlaps with the time-range, but we're just * busy the entire time. */ - public function testVAvailabilitySimple() + public function testVAvailabilitySimple(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( "FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T110000Z/20110101T120000Z\n". "FREEBUSY:20110101T120000Z/20110101T130000Z\n". 'FREEBUSY;FBTYPE=BUSY-UNAVAILABLE:20110101T130000Z/20110103T110000Z', @@ -547,7 +546,7 @@ public function testVAvailabilitySimple() * This VAVAILABILITY object does not overlap at all with the freebusy * report, so it should be ignored. */ - public function testVAvailabilityIrrelevant() + public function testVAvailabilityIrrelevant(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T120000Z/20110101T130000Z', $blob, null, @@ -584,7 +583,7 @@ public function testVAvailabilityIrrelevant() * This VAVAILABILITY object has a 9am-5pm AVAILABLE object for office * hours. */ - public function testVAvailabilityOfficeHours() + public function testVAvailabilityOfficeHours(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n". "FREEBUSY:20110101T120000Z/20110101T130000Z\n". "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n", @@ -625,7 +624,7 @@ public function testVAvailabilityOfficeHours() * This test has the same office hours, but has a vacation blocked off for * the relevant time, using a higher priority. (lower number). */ - public function testVAvailabilityOfficeHoursVacation() + public function testVAvailabilityOfficeHoursVacation(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( 'FREEBUSY:20110101T110000Z/20110103T110000Z', $blob, null, @@ -673,7 +672,7 @@ public function testVAvailabilityOfficeHoursVacation() * * The end-result is that the vacation VAVAILABILITY is completely ignored. */ - public function testVAvailabilityOfficeHoursVacation2() + public function testVAvailabilityOfficeHoursVacation2(): void { $blob = <<assertFreeBusyReport( + self::assertFreeBusyReport( "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T110000Z/20110101T120000Z\n". "FREEBUSY:20110101T120000Z/20110101T130000Z\n". "FREEBUSY;FBTYPE=BUSY-TENTATIVE:20110101T130000Z/20110103T090000Z\n", diff --git a/tests/VObject/GoogleColonEscapingTest.php b/tests/VObject/GoogleColonEscapingTest.php index 48bbde07b..fa2ba8a7f 100644 --- a/tests/VObject/GoogleColonEscapingTest.php +++ b/tests/VObject/GoogleColonEscapingTest.php @@ -12,7 +12,7 @@ */ class GoogleColonEscapingTest extends TestCase { - public function testDecode() + public function testDecode(): void { $vcard = <<assertEquals('http://www.rooftopsolutions.nl/', $vobj->URL->getValue()); + self::assertEquals('http://www.rooftopsolutions.nl/', $vobj->URL->getValue()); } } diff --git a/tests/VObject/ICalendar/AttachParseTest.php b/tests/VObject/ICalendar/AttachParseTest.php index e6e3d8685..cb54eb341 100644 --- a/tests/VObject/ICalendar/AttachParseTest.php +++ b/tests/VObject/ICalendar/AttachParseTest.php @@ -11,7 +11,7 @@ class AttachParseTest extends TestCase /** * See issue #128 for more info. */ - public function testParseAttach() + public function testParseAttach(): void { $vcal = <<VEVENT->ATTACH; - $this->assertInstanceOf(Uri::class, $prop); - $this->assertEquals('ftp://example.com/pub/reports/r-960812.ps', $prop->getValue()); + self::assertInstanceOf(Uri::class, $prop); + self::assertEquals('ftp://example.com/pub/reports/r-960812.ps', $prop->getValue()); } } diff --git a/tests/VObject/ITip/BrokerAttendeeReplyTest.php b/tests/VObject/ITip/BrokerAttendeeReplyTest.php index 284075adf..98942af41 100644 --- a/tests/VObject/ITip/BrokerAttendeeReplyTest.php +++ b/tests/VObject/ITip/BrokerAttendeeReplyTest.php @@ -4,7 +4,7 @@ class BrokerAttendeeReplyTest extends BrokerTester { - public function testAccepted() + public function testAccepted(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testAcceptedWithTz() + public function testAcceptedWithTz(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testRecurringReply() + public function testRecurringReply(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testRecurringAllDay() + public function testRecurringAllDay(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testNoChange() + public function testNoChange(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testNoChangeForceSend() + public function testNoChangeForceSend(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testNoRelevantAttendee() + public function testNoRelevantAttendee(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testDeclined() + public function testDeclined(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testDeclinedCancelledEvent() + public function testDeclinedCancelledEvent(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); @@ -910,7 +908,7 @@ public function testDeclinedCancelledEvent() * For any other attendance status, the new status would have been * declined, but for this, no message should we sent. */ - public function testDontCreateReplyWhenEventWasDeclined() + public function testDontCreateReplyWhenEventWasDeclined(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testScheduleAgentOnOrganizer() + public function testScheduleAgentOnOrganizer(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected); } - public function testAcceptedAllDay() + public function testAcceptedAllDay(): void { $oldMessage = << 'foobar', @@ -1129,7 +1123,7 @@ public function testReplyNoMasterEvent() * * @depends testAccepted */ - public function testPartyCrasher() + public function testPartyCrasher(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testOrganizerDeleteWithDuration() + public function testOrganizerDeleteWithDuration(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testAttendeeDeleteWithDtend() + public function testAttendeeDeleteWithDtend(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:one@example.org'); } - public function testAttendeeReplyWithDuration() + public function testAttendeeReplyWithDuration(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:one@example.org'); } - public function testAttendeeDeleteCancelledEvent() + public function testAttendeeDeleteCancelledEvent(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:one@example.org'); } - public function testNoCalendar() + public function testNoCalendar(): void { $this->parse(null, null, [], 'mailto:one@example.org'); } - public function testVTodo() + public function testVTodo(): void { $oldMessage = <<parse(null, $message, []); + $this->parse(null, $message, []); } - public function testVTODO() + public function testVTODO(): void { $message = <<parse(null, $message, []); + $this->parse(null, $message, []); } - public function testSimpleInvite() + public function testSimpleInvite(): void { $message = <<parse(null, $message, $expected, 'mailto:strunk@example.org'); } - public function testBrokenEventUIDMisMatch() + public function testBrokenEventUIDMisMatch(): void { $this->expectException(ITipException::class); $message = <<parse(null, $message, [], 'mailto:strunk@example.org'); } - public function testBrokenEventOrganizerMisMatch() + public function testBrokenEventOrganizerMisMatch(): void { $this->expectException(ITipException::class); $message = <<parse(null, $message, [], 'mailto:strunk@example.org'); } - public function testRecurrenceInvite() + public function testRecurrenceInvite(): void { $message = <<parse(null, $message, $expected, 'mailto:strunk@example.org'); } - public function testRecurrenceInvite2() + public function testRecurrenceInvite2(): void { // This method tests a nearly identical path, but in this case the // master event does not have an EXDATE. @@ -281,7 +283,7 @@ public function testRecurrenceInvite2() END:VCALENDAR ICS; - $version = \Sabre\VObject\Version::VERSION; + $version = Version::VERSION; $expected = [ [ @@ -381,7 +383,7 @@ public function testRecurrenceInvite2() $this->parse(null, $message, $expected, 'mailto:strunk@example.org'); } - public function testRecurrenceInvite3() + public function testRecurrenceInvite3(): void { // This method tests a complex rrule $message = <<parse(null, $message, $expected, 'mailto:strunk@example.org'); } - public function testScheduleAgentClient() + public function testScheduleAgentClient(): void { $message = <<parse(null, $message, [], 'mailto:strunk@example.org'); } - public function testMultipleUID() + public function testMultipleUID(): void { $this->expectException(ITipException::class); $message = <<parse(null, $message, [], 'mailto:strunk@example.org'); } - public function testChangingOrganizers() + public function testChangingOrganizers(): void { $this->expectException(SameOrganizerForAllComponentsException::class); $message = <<parse(null, $message, [], 'mailto:strunk@example.org'); } - public function testCaseInsensitiveOrganizers() + public function testCaseInsensitiveOrganizers(): void { $message = <<process($itip, null, $expected); + $this->process($itip, null, $expected); } - public function testRequestUpdate() + public function testRequestUpdate(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testCancel() + public function testCancel(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testCancelNoExistingEvent() + public function testCancelNoExistingEvent(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testUnsupportedComponent() + public function testUnsupportedComponent(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testUnsupportedMethod() + public function testUnsupportedMethod(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } } diff --git a/tests/VObject/ITip/BrokerProcessReplyTest.php b/tests/VObject/ITip/BrokerProcessReplyTest.php index bbfd6c419..064d5cb48 100644 --- a/tests/VObject/ITip/BrokerProcessReplyTest.php +++ b/tests/VObject/ITip/BrokerProcessReplyTest.php @@ -4,7 +4,7 @@ class BrokerProcessReplyTest extends BrokerTester { - public function testReplyNoOriginal() + public function testReplyNoOriginal(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyAccept() + public function testReplyAccept(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyWithTz() + public function testReplyWithTz(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyRequestStatus() + public function testReplyRequestStatus(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyPartyCrasher() + public function testReplyPartyCrasher(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyNewException() + public function testReplyNewException(): void { // This is a reply to 1 instance of a recurring event. This should // automatically create an exception. @@ -310,10 +310,10 @@ public function testReplyNewException() END:VCALENDAR ICS; - $result = $this->process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyNewExceptionTz() + public function testReplyNewExceptionTz(): void { // This is a reply to 1 instance of a recurring event. This should // automatically create an exception. @@ -370,10 +370,10 @@ public function testReplyNewExceptionTz() END:VCALENDAR ICS; - $result = $this->process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyPartyCrashCreateException() + public function testReplyPartyCrashCreateException(): void { // IN this test there's a recurring event that has an exception. The // exception is missing the attendee. @@ -431,10 +431,10 @@ public function testReplyPartyCrashCreateException() END:VCALENDAR ICS; - $result = $this->process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyNewExceptionNoMasterEvent() + public function testReplyNewExceptionNoMasterEvent(): void { /** * This iTip message would normally create a new exception, but the @@ -473,13 +473,13 @@ public function testReplyNewExceptionNoMasterEvent() ICS; $expected = null; - $result = $this->process($itip, $old, $expected); + $this->process($itip, $old, $expected); } /** * @depends testReplyAccept */ - public function testReplyAcceptUpdateRSVP() + public function testReplyAcceptUpdateRSVP(): void { $itip = <<process($itip, $old, $expected); + $this->process($itip, $old, $expected); } - public function testReplyNewExceptionFirstOccurence() + public function testReplyNewExceptionFirstOccurrence(): void { // This is a reply to 1 instance of a recurring event. This should // automatically create an exception. @@ -578,6 +578,6 @@ public function testReplyNewExceptionFirstOccurence() END:VCALENDAR ICS; - $result = $this->process($itip, $old, $expected); + $this->process($itip, $old, $expected); } } diff --git a/tests/VObject/ITip/BrokerSignificantChangesTest.php b/tests/VObject/ITip/BrokerSignificantChangesTest.php index a20d55025..44843615e 100644 --- a/tests/VObject/ITip/BrokerSignificantChangesTest.php +++ b/tests/VObject/ITip/BrokerSignificantChangesTest.php @@ -7,7 +7,7 @@ class BrokerSignificantChangesTest extends BrokerTester /** * Check significant changes detection (no change). */ - public function testSignificantChangesNoChange() + public function testSignificantChangesNoChange(): void { $old = <<parseEvent($newMessage, $currentUser, $oldMessage); - $this->assertEquals(count($expected), count($result)); + self::assertSameSize($expected, $result); foreach ($expected as $index => $ex) { $message = $result[$index]; foreach ($ex as $key => $val) { if ('message' === $key) { - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $val, $message->message->serialize() ); } else { - $this->assertEquals($val, $message->$key); + self::assertEquals($val, $message->$key); } } } } - public function process($input, $existingObject = null, $expected = false) + /** + * @throws ParseException + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws InvalidDataException + */ + public function process($input, $existingObject = null, $expected = false): void { - $version = \Sabre\VObject\Version::VERSION; + $version = Version::VERSION; $vcal = Reader::read($input); - $mainComponent = new \Sabre\VObject\Component\VEvent($vcal, 'VEVENT'); + $mainComponent = new VEvent($vcal, 'VEVENT'); foreach ($vcal->getComponents() as $mainComponent) { if ('VEVENT' === $mainComponent->name) { break; @@ -80,12 +93,12 @@ public function process($input, $existingObject = null, $expected = false) $result = $broker->processMessage($message, $existingObject); if (is_null($expected)) { - $this->assertTrue(!$result); + self::assertTrue(!$result); return; } - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $result ); diff --git a/tests/VObject/ITip/BrokerTimezoneInParseEventInfoWithoutMasterTest.php b/tests/VObject/ITip/BrokerTimezoneInParseEventInfoWithoutMasterTest.php index 1635be742..e3f18f15e 100644 --- a/tests/VObject/ITip/BrokerTimezoneInParseEventInfoWithoutMasterTest.php +++ b/tests/VObject/ITip/BrokerTimezoneInParseEventInfoWithoutMasterTest.php @@ -7,7 +7,7 @@ class BrokerTimezoneInParseEventInfoWithoutMasterTest extends TestCase { - public function testTimezoneInParseEventInfoWithoutMaster() + public function testTimezoneInParseEventInfoWithoutMaster(): void { $calendar = <<setAccessible(true); $data = $reflectionMethod->invoke($broker, $calendar); - $this->assertInstanceOf('DateTimeZone', $data['timezone']); - $this->assertEquals($data['timezone']->getName(), 'Europe/Minsk'); + self::assertInstanceOf('DateTimeZone', $data['timezone']); + self::assertEquals('Europe/Minsk', $data['timezone']->getName()); } } diff --git a/tests/VObject/ITip/BrokerUpdateEventTest.php b/tests/VObject/ITip/BrokerUpdateEventTest.php index e93f89652..1497bb711 100644 --- a/tests/VObject/ITip/BrokerUpdateEventTest.php +++ b/tests/VObject/ITip/BrokerUpdateEventTest.php @@ -2,9 +2,11 @@ namespace Sabre\VObject\ITip; +use Sabre\VObject\Version; + class BrokerUpdateEventTest extends BrokerTester { - public function testInviteChange() + public function testInviteChange(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testInviteChangeFromNonSchedulingToSchedulingObject() + public function testInviteChangeFromNonSchedulingToSchedulingObject(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testInviteChangeFromSchedulingToNonSchedulingObject() + public function testInviteChangeFromSchedulingToNonSchedulingObject(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testNoAttendees() + public function testNoAttendees(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testRemoveInstance() + public function testRemoveInstance(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testInviteNoChange() + public function testInviteNoChange(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testInviteNoChangeForceSend() + public function testInviteNoChangeForceSend(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testInviteRemoveAttendees() + public function testInviteRemoveAttendees(): void { $oldMessage = <<parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); + $this->parse($oldMessage, $newMessage, $expected, 'mailto:strunk@example.org'); } - public function testInviteChangeExdateOrder() + public function testInviteChangeExdateOrder(): void { $oldMessage = <<assertFalse($message->getScheduleStatus()); + self::assertFalse($message->getScheduleStatus()); } - public function testScheduleStatus() + public function testScheduleStatus(): void { $message = new Message(); $message->scheduleStatus = '1.2;Delivered'; - $this->assertEquals('1.2', $message->getScheduleStatus()); + self::assertEquals('1.2', $message->getScheduleStatus()); } - public function testUnexpectedScheduleStatus() + public function testUnexpectedScheduleStatus(): void { $message = new Message(); $message->scheduleStatus = '9.9.9'; - $this->assertEquals('9.9.9', $message->getScheduleStatus()); + self::assertEquals('9.9.9', $message->getScheduleStatus()); } } diff --git a/tests/VObject/Issue153Test.php b/tests/VObject/Issue153Test.php index 309025041..83e56cf50 100644 --- a/tests/VObject/Issue153Test.php +++ b/tests/VObject/Issue153Test.php @@ -6,9 +6,9 @@ class Issue153Test extends TestCase { - public function testRead() + public function testRead(): void { $obj = Reader::read(file_get_contents(dirname(__FILE__).'/issue153.vcf')); - $this->assertEquals('Test Benutzer', (string) $obj->FN); + self::assertEquals('Test Benutzer', (string) $obj->FN); } } diff --git a/tests/VObject/Issue259Test.php b/tests/VObject/Issue259Test.php index 3227fcd56..5c014ad3c 100644 --- a/tests/VObject/Issue259Test.php +++ b/tests/VObject/Issue259Test.php @@ -6,7 +6,7 @@ class Issue259Test extends TestCase { - public function testParsingJcalWithUntil() + public function testParsingJcalWithUntil(): void { $jcalWithUntil = '["vcalendar",[],[["vevent",[["uid",{},"text","dd1f7d29"],["organizer",{"cn":"robert"},"cal-address","mailto:robert@robert.com"],["dtstart",{"tzid":"Europe/Berlin"},"date-time","2015-10-21T12:00:00"],["dtend",{"tzid":"Europe/Berlin"},"date-time","2015-10-21T13:00:00"],["transp",{},"text","OPAQUE"],["rrule",{},"recur",{"freq":"MONTHLY","until":"2016-01-01T22:00:00Z"}]],[]]]]'; $parser = new Parser\Json(); @@ -17,7 +17,7 @@ public function testParsingJcalWithUntil() $event = reset($eventAsArray); $rruleAsArray = $event->select('RRULE'); $rrule = reset($rruleAsArray); - $this->assertNotNull($rrule); - $this->assertEquals($rrule->getValue(), 'FREQ=MONTHLY;UNTIL=20160101T220000Z'); + self::assertNotNull($rrule); + self::assertEquals('FREQ=MONTHLY;UNTIL=20160101T220000Z', $rrule->getValue()); } } diff --git a/tests/VObject/Issue36WorkAroundTest.php b/tests/VObject/Issue36WorkAroundTest.php index 1afd3d184..e6c4f254e 100644 --- a/tests/VObject/Issue36WorkAroundTest.php +++ b/tests/VObject/Issue36WorkAroundTest.php @@ -6,7 +6,7 @@ class Issue36WorkAroundTest extends TestCase { - public function testWorkaround() + public function testWorkaround(): void { // See https://github.com/fruux/sabre-vobject/issues/36 $event = <<assertInstanceOf(Recur\EventIterator::class, $it); + self::assertInstanceOf(Recur\EventIterator::class, $it); } } diff --git a/tests/VObject/Issue40Test.php b/tests/VObject/Issue40Test.php index 1cf9986e9..3d280ed4d 100644 --- a/tests/VObject/Issue40Test.php +++ b/tests/VObject/Issue40Test.php @@ -11,7 +11,7 @@ */ class Issue40Test extends TestCase { - public function testEncode() + public function testEncode(): void { $card = new Component\VCard(); $card->add('N', ['van der Harten', ['Rene', 'J.'], '', 'Sir', 'R.D.O.N.'], ['SORT-AS' => ['Harten', 'Rene']]); @@ -27,6 +27,6 @@ public function testEncode() '', ]); - $this->assertEquals($expected, $card->serialize()); + self::assertEquals($expected, $card->serialize()); } } diff --git a/tests/VObject/Issue467Test.php b/tests/VObject/Issue467Test.php new file mode 100644 index 000000000..27f1b49bc --- /dev/null +++ b/tests/VObject/Issue467Test.php @@ -0,0 +1,56 @@ +VEVENT->VALARM->TRIGGER->getDateInterval()); + } +} diff --git a/tests/VObject/Issue64Test.php b/tests/VObject/Issue64Test.php index 2e623baa8..110f91fa2 100644 --- a/tests/VObject/Issue64Test.php +++ b/tests/VObject/Issue64Test.php @@ -6,14 +6,14 @@ class Issue64Test extends TestCase { - public function testRead() + public function testRead(): void { $vcard = Reader::read(file_get_contents(dirname(__FILE__).'/issue64.vcf')); - $vcard = $vcard->convert(\Sabre\VObject\Document::VCARD30); + $vcard = $vcard->convert(Document::VCARD30); $vcard = $vcard->serialize(); $converted = Reader::read($vcard); - $this->assertInstanceOf(Component\VCard::class, $converted); + self::assertInstanceOf(Component\VCard::class, $converted); } } diff --git a/tests/VObject/Issue96Test.php b/tests/VObject/Issue96Test.php index 88803a3e0..137149e8f 100644 --- a/tests/VObject/Issue96Test.php +++ b/tests/VObject/Issue96Test.php @@ -6,7 +6,7 @@ class Issue96Test extends TestCase { - public function testRead() + public function testRead(): void { $input = <<assertInstanceOf(Component\VCard::class, $vcard); - $this->assertEquals('http://www.example.org', $vcard->URL->getValue()); + self::assertInstanceOf(Component\VCard::class, $vcard); + self::assertEquals('http://www.example.org', $vcard->URL->getValue()); } } diff --git a/tests/VObject/IssueUndefinedIndexTest.php b/tests/VObject/IssueUndefinedIndexTest.php index 7ed214a19..5085fbd20 100644 --- a/tests/VObject/IssueUndefinedIndexTest.php +++ b/tests/VObject/IssueUndefinedIndexTest.php @@ -6,7 +6,7 @@ class IssueUndefinedIndexTest extends TestCase { - public function testRead() + public function testRead(): void { $this->expectException(ParseException::class); $input = <<assertEquals($expected, $cal->jsonSerialize()); + self::assertEquals($expected, $cal->jsonSerialize()); } } diff --git a/tests/VObject/JCardTest.php b/tests/VObject/JCardTest.php index 1864f666d..cbd56ba97 100644 --- a/tests/VObject/JCardTest.php +++ b/tests/VObject/JCardTest.php @@ -6,7 +6,7 @@ class JCardTest extends TestCase { - public function testToJCard() + public function testToJCard(): void { $card = new Component\VCard([ 'VERSION' => '4.0', @@ -189,6 +189,6 @@ public function testToJCard() ], ]; - $this->assertEquals($expected, $card->jsonSerialize()); + self::assertEquals($expected, $card->jsonSerialize()); } } diff --git a/tests/VObject/LineFoldingIssueTest.php b/tests/VObject/LineFoldingIssueTest.php index 3d4f26af5..5e636d36c 100644 --- a/tests/VObject/LineFoldingIssueTest.php +++ b/tests/VObject/LineFoldingIssueTest.php @@ -6,7 +6,7 @@ class LineFoldingIssueTest extends TestCase { - public function testRead() + public function testRead(): void { $event = <<assertEquals($event, $obj->serialize()); + self::assertEquals($event, $obj->serialize()); } } diff --git a/tests/VObject/ParameterTest.php b/tests/VObject/ParameterTest.php index 0e23b0620..4c9f2c774 100644 --- a/tests/VObject/ParameterTest.php +++ b/tests/VObject/ParameterTest.php @@ -6,79 +6,79 @@ class ParameterTest extends TestCase { - public function testSetup() + public function testSetup(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', 'value'); - $this->assertEquals('NAME', $param->name); - $this->assertEquals('value', $param->getValue()); + self::assertEquals('NAME', $param->name); + self::assertEquals('value', $param->getValue()); } - public function testSetupNameLess() + public function testSetupNameLess(): void { $card = new Component\VCard(); $param = new Parameter($card, null, 'URL'); - $this->assertEquals('VALUE', $param->name); - $this->assertEquals('URL', $param->getValue()); - $this->assertTrue($param->noName); + self::assertEquals('VALUE', $param->name); + self::assertEquals('URL', $param->getValue()); + self::assertTrue($param->noName); } - public function testModify() + public function testModify(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', null); $param->addValue(1); - $this->assertEquals([1], $param->getParts()); + self::assertEquals([1], $param->getParts()); $param->setParts([1, 2]); - $this->assertEquals([1, 2], $param->getParts()); + self::assertEquals([1, 2], $param->getParts()); $param->addValue(3); - $this->assertEquals([1, 2, 3], $param->getParts()); + self::assertEquals([1, 2, 3], $param->getParts()); $param->setValue(4); $param->addValue(5); - $this->assertEquals([4, 5], $param->getParts()); + self::assertEquals([4, 5], $param->getParts()); } - public function testCastToString() + public function testCastToString(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', 'value'); - $this->assertEquals('value', $param->__toString()); - $this->assertEquals('value', (string) $param); + self::assertEquals('value', $param->__toString()); + self::assertEquals('value', (string) $param); } - public function testCastNullToString() + public function testCastNullToString(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', null); - $this->assertEquals('', $param->__toString()); - $this->assertEquals('', (string) $param); + self::assertEquals('', $param->__toString()); + self::assertEquals('', (string) $param); } - public function testSerialize() + public function testSerialize(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', 'value'); - $this->assertEquals('NAME=value', $param->serialize()); + self::assertEquals('NAME=value', $param->serialize()); } - public function testSerializeEmpty() + public function testSerializeEmpty(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', null); - $this->assertEquals('NAME=', $param->serialize()); + self::assertEquals('NAME=', $param->serialize()); } - public function testSerializeComplex() + public function testSerializeComplex(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', ['val1', 'val2;', 'val3^', "val4\n", 'val5"']); - $this->assertEquals('NAME=val1,"val2;","val3^^","val4^n","val5^\'"', $param->serialize()); + self::assertEquals('NAME=val1,"val2;","val3^^","val4^n","val5^\'"', $param->serialize()); } /** @@ -87,14 +87,14 @@ public function testSerializeComplex() * * So we specifically added support for that. */ - public function testSerializePlusSign() + public function testSerializePlusSign(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'EMAIL', 'user+something@example.org'); - $this->assertEquals('EMAIL="user+something@example.org"', $param->serialize()); + self::assertEquals('EMAIL="user+something@example.org"', $param->serialize()); } - public function testIterate() + public function testIterate(): void { $cal = new Component\VCalendar(); @@ -105,20 +105,20 @@ public function testIterate() $result[] = $value; } - $this->assertEquals([1, 2, 3, 4], $result); + self::assertEquals([1, 2, 3, 4], $result); } - public function testSerializeColon() + public function testSerializeColon(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', 'va:lue'); - $this->assertEquals('NAME="va:lue"', $param->serialize()); + self::assertEquals('NAME="va:lue"', $param->serialize()); } - public function testSerializeSemiColon() + public function testSerializeSemiColon(): void { $cal = new Component\VCalendar(); $param = new Parameter($cal, 'name', 'va;lue'); - $this->assertEquals('NAME="va;lue"', $param->serialize()); + self::assertEquals('NAME="va;lue"', $param->serialize()); } } diff --git a/tests/VObject/Parser/JsonTest.php b/tests/VObject/Parser/JsonTest.php index e1c701489..996e834e6 100644 --- a/tests/VObject/Parser/JsonTest.php +++ b/tests/VObject/Parser/JsonTest.php @@ -8,7 +8,7 @@ class JsonTest extends TestCase { - public function testRoundTripJCard() + public function testRoundTripJCard(): void { $input = [ 'vcard', @@ -189,15 +189,15 @@ public function testRoundTripJCard() END:VCARD VCF; - $this->assertEquals($expected, str_replace("\r", '', $result)); + self::assertEquals($expected, str_replace("\r", '', $result)); - $this->assertEquals( + self::assertEquals( $input, $vobj->jsonSerialize() ); } - public function testRoundTripJCal() + public function testRoundTripJCal(): void { $input = [ 'vcalendar', @@ -345,15 +345,15 @@ public function testRoundTripJCal() END:VCALENDAR VCF; - $this->assertEquals($expected, str_replace("\r", '', $result)); + self::assertEquals($expected, str_replace("\r", '', $result)); - $this->assertEquals( + self::assertEquals( $input, $vobj->jsonSerialize() ); } - public function testParseStreamArg() + public function testParseStreamArg(): void { $input = [ 'vcard', @@ -369,10 +369,10 @@ public function testParseStreamArg() rewind($stream); $result = VObject\Reader::readJson($stream, 0); - $this->assertEquals('foo', $result->FN->getValue()); + self::assertEquals('foo', $result->FN->getValue()); } - public function testParseInvalidData() + public function testParseInvalidData(): void { $this->expectException(ParseException::class); $json = new Json(); diff --git a/tests/VObject/Parser/MimeDirTest.php b/tests/VObject/Parser/MimeDirTest.php index 183c9ce4c..24656f886 100644 --- a/tests/VObject/Parser/MimeDirTest.php +++ b/tests/VObject/Parser/MimeDirTest.php @@ -3,6 +3,7 @@ namespace Sabre\VObject\Parser; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCalendar; use Sabre\VObject\ParseException; /** @@ -11,14 +12,14 @@ */ class MimeDirTest extends TestCase { - public function testParseError() + public function testParseError(): void { $this->expectException(ParseException::class); $mimeDir = new MimeDir(); $mimeDir->parse(fopen(__FILE__, 'a+')); } - public function testDecodeLatin1() + public function testDecodeLatin1(): void { $vcard = <<setCharset('ISO-8859-1'); $vcard = $mimeDir->parse($vcard); - $this->assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue()); + self::assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue()); } - public function testDecodeInlineLatin1() + public function testDecodeInlineLatin1(): void { $vcard = <<parse($vcard); - $this->assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue()); + self::assertEquals("umlaut u - \xC3\xBC", $vcard->FN->getValue()); } - public function testIgnoreCharsetVCard30() + public function testIgnoreCharsetVCard30(): void { $vcard = <<parse($vcard); - $this->assertEquals("foo-bar - \xFC", $vcard->FN->getValue()); + self::assertEquals("foo-bar - \xFC", $vcard->FN->getValue()); } - public function testDontDecodeLatin1() + public function testDontDecodeLatin1(): void { $vcard = <<assertEquals("umlaut u - \xFC", $vcard->FN->getValue()); + self::assertEquals("umlaut u - \xFC", $vcard->FN->getValue()); } - public function testDecodeUnsupportedCharset() + public function testDecodeUnsupportedCharset(): void { $this->expectException(\InvalidArgumentException::class); $mimeDir = new MimeDir(); $mimeDir->setCharset('foobar'); } - public function testDecodeUnsupportedInlineCharset() + public function testDecodeUnsupportedInlineCharset(): void { $this->expectException(ParseException::class); $vcard = <<parse($vcard); } - public function testDecodeWindows1252() + public function testDecodeWindows1252(): void { $vcard = <<setCharset('Windows-1252'); $vcard = $mimeDir->parse($vcard); - $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue()); + self::assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue()); } - public function testDecodeWindows1252Inline() + public function testDecodeWindows1252Inline(): void { $vcard = <<parse($vcard); - $this->assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue()); + self::assertEquals("Euro \xE2\x82\xAC", $vcard->FN->getValue()); } - public function testCaseInsensitiveInlineCharset() + public function testCaseInsensitiveInlineCharset(): void { $vcard = <<parse($vcard); // we can do a simple assertion here. As long as we don't get an exception, everything is thing - $this->assertEquals('Euro', $vcard->FN->getValue()); - $this->assertEquals('Test2', $vcard->N->getValue()); + self::assertEquals('Euro', $vcard->FN->getValue()); + self::assertEquals('Test2', $vcard->N->getValue()); + } + + public function testParsingTwiceSameContent(): void + { + $card = <<parse($card); + // we can do a simple assertion here. As long as we don't get an exception, everything is fine + self::assertEquals('20220612', $vcard->VEVENT->DTSTART->getValue()); + } + + /** + * @covers \Sabre\VObject\Parser\MimeDir::readProperty + * + * @dataProvider provideBrokenVCalendar + */ + public function testBrokenMultilineContentDoesNotBreakImportWhenSetToIgnoreBrokenLines(string $vcalendar): void + { + $mimeDir = new MimeDir(null, MimeDir::OPTION_IGNORE_INVALID_LINES); + $vcalendar = $mimeDir->parse($vcalendar); + self::assertInstanceOf(VCalendar::class, $vcalendar); + } + + /** + * @covers \Sabre\VObject\Parser\MimeDir::readProperty + * + * @dataProvider provideBrokenVCalendar + * + * @param string $vcalendar + */ + public function testBrokenMultilineContentDoesBreakImport($vcalendar): void + { + $mimeDir = new MimeDir(); + $this->expectException(ParseException::class); + $mimeDir->parse($vcalendar); + } + + public function provideBrokenVCalendar(): array + { + return [[<<assertInstanceOf(Component::class, $result); - $this->assertEquals('VCARD', $result->name); - $this->assertEquals(1, count($result->children())); - $this->assertEquals('Aachen', $this->getPropertyValue($result->LABEL)); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCARD', $result->name); + self::assertCount(1, $result->children()); + self::assertEquals('Aachen', $this->getPropertyValue($result->LABEL)); } - public function testReadQuotedPrintableNewlineSoft() + public function testReadQuotedPrintableNewlineSoft(): void { $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aa=\r\n ch=\r\n en\r\nEND:VCARD"; $result = Reader::read($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCARD', $result->name); - $this->assertEquals(1, count($result->children())); - $this->assertEquals('Aachen', $this->getPropertyValue($result->LABEL)); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCARD', $result->name); + self::assertCount(1, $result->children()); + self::assertEquals('Aachen', $this->getPropertyValue($result->LABEL)); } - public function testReadQuotedPrintableNewlineHard() + public function testReadQuotedPrintableNewlineHard(): void { $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\n Germany\r\nEND:VCARD"; $result = Reader::read($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCARD', $result->name); - $this->assertEquals(1, count($result->children())); - $this->assertEquals("Aachen\r\nGermany", $this->getPropertyValue($result->LABEL)); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCARD', $result->name); + self::assertCount(1, $result->children()); + self::assertEquals("Aachen\r\nGermany", $this->getPropertyValue($result->LABEL)); } - public function testReadQuotedPrintableCompatibilityMS() + public function testReadQuotedPrintableCompatibilityMS(): void { $data = "BEGIN:VCARD\r\nLABEL;ENCODING=QUOTED-PRINTABLE:Aachen=0D=0A=\r\nDeutschland:okay\r\nEND:VCARD"; $result = Reader::read($data, Reader::OPTION_FORGIVING); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCARD', $result->name); - $this->assertEquals(1, count($result->children())); - $this->assertEquals("Aachen\r\nDeutschland:okay", $this->getPropertyValue($result->LABEL)); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCARD', $result->name); + self::assertCount(1, $result->children()); + self::assertEquals("Aachen\r\nDeutschland:okay", $this->getPropertyValue($result->LABEL)); } - public function testReadQuotesPrintableCompoundValues() + public function testReadQuotesPrintableCompoundValues(): void { $data = <<assertEquals([ + self::assertEquals([ '', '', 'Münster Str. 1', 'Münster', '', '48143', 'Deutschland', ], $result->ADR->getParts()); } - private function getPropertyValue(\Sabre\VObject\Property $property) + private function getPropertyValue(Property $property): string { return (string) $property; diff --git a/tests/VObject/Parser/XmlTest.php b/tests/VObject/Parser/XmlTest.php index 46ee30ce2..2276f7fdf 100644 --- a/tests/VObject/Parser/XmlTest.php +++ b/tests/VObject/Parser/XmlTest.php @@ -9,10 +9,10 @@ class XmlTest extends TestCase { use VObject\PHPUnitAssertions; - public function testRFC6321Example1() + public function testRFC6321Example1(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -48,7 +48,7 @@ public function testRFC6321Example1() XML -, + , 'BEGIN:VCALENDAR'."\n". // VERSION comes first because this is required by vCard 4.0. 'VERSION:2.0'."\n". @@ -64,7 +64,7 @@ public function testRFC6321Example1() ); } - public function testRFC6321Example2() + public function testRFC6321Example2(): void { $xml = << @@ -212,7 +212,7 @@ public function testRFC6321Example2() XML; $component = VObject\Reader::readXML($xml); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( 'BEGIN:VCALENDAR'."\n". 'VERSION:2.0'."\n". 'PRODID:-//Example Inc.//Example Client//EN'."\n". @@ -262,16 +262,16 @@ public function testRFC6321Example2() /** * iCalendar Stream. */ - public function testRFC6321Section3Part2() + public function testRFC6321Section3Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< XML -, + , 'BEGIN:VCALENDAR'."\n". 'END:VCALENDAR'."\n" ); @@ -280,10 +280,10 @@ public function testRFC6321Section3Part2() /** * All components exist. */ - public function testRFC6321Section3Part3() + public function testRFC6321Section3Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -300,7 +300,7 @@ public function testRFC6321Section3Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'BEGIN:VTIMEZONE'."\n". 'END:VTIMEZONE'."\n". @@ -325,10 +325,10 @@ public function testRFC6321Section3Part3() /** * Properties, Special Cases, GEO. */ - public function testRFC6321Section3Part4Part1Part2() + public function testRFC6321Section3Part4Part1Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -341,7 +341,7 @@ public function testRFC6321Section3Part4Part1Part2() XML -, + , 'BEGIN:VCALENDAR'."\n". 'GEO:37.386013;-122.082932'."\n". 'END:VCALENDAR'."\n" @@ -351,11 +351,11 @@ public function testRFC6321Section3Part4Part1Part2() /** * Properties, Special Cases, REQUEST-STATUS. */ - public function testRFC6321Section3Part4Part1Part3() + public function testRFC6321Section3Part4Part1Part3(): void { // Example 1 of RFC5545, Section 3.8.8.3. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -368,15 +368,15 @@ public function testRFC6321Section3Part4Part1Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'REQUEST-STATUS:2.0;Success'."\n". 'END:VCALENDAR'."\n" ); // Example 2 of RFC5545, Section 3.8.8.3. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -390,15 +390,15 @@ public function testRFC6321Section3Part4Part1Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'REQUEST-STATUS:3.1;Invalid property value;DTSTART:96-Apr-01'."\n". 'END:VCALENDAR'."\n" ); // Example 3 of RFC5545, Section 3.8.8.3. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -412,7 +412,7 @@ public function testRFC6321Section3Part4Part1Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'REQUEST-STATUS:2.8;Success\, repeating event ignored. Scheduled as a single'."\n". ' event.;RRULE:FREQ=WEEKLY\;INTERVAL=2'."\n". @@ -420,8 +420,8 @@ public function testRFC6321Section3Part4Part1Part3() ); // Example 4 of RFC5545, Section 3.8.8.3. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -434,15 +434,15 @@ public function testRFC6321Section3Part4Part1Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'REQUEST-STATUS:4.1;Event conflict. Date-time is busy.'."\n". 'END:VCALENDAR'."\n" ); // Example 5 of RFC5545, Section 3.8.8.3. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -456,7 +456,7 @@ public function testRFC6321Section3Part4Part1Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'REQUEST-STATUS:3.7;Invalid calendar user;ATTENDEE:mailto:jsmith@example.com'."\n". 'END:VCALENDAR'."\n" @@ -466,10 +466,10 @@ public function testRFC6321Section3Part4Part1Part3() /** * Values, Binary. */ - public function testRFC6321Section3Part6Part1() + public function testRFC6321Section3Part6Part1(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -481,15 +481,15 @@ public function testRFC6321Section3Part6Part1() XML -, + , 'BEGIN:VCALENDAR'."\n". 'ATTACH:SGVsbG8gV29ybGQh'."\n". 'END:VCALENDAR'."\n" ); // In vCard 4, BINARY no longer exists and is replaced by URI. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -501,7 +501,7 @@ public function testRFC6321Section3Part6Part1() XML -, + , 'BEGIN:VCALENDAR'."\n". 'ATTACH:SGVsbG8gV29ybGQh'."\n". 'END:VCALENDAR'."\n" @@ -511,10 +511,10 @@ public function testRFC6321Section3Part6Part1() /** * Values, Boolean. */ - public function testRFC6321Section3Part6Part2() + public function testRFC6321Section3Part6Part2(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -529,7 +529,7 @@ public function testRFC6321Section3Part6Part2() XML -, + , 'BEGIN:VCALENDAR'."\n". 'ATTENDEE;RSVP=true:mailto:cyrus@example.com'."\n". 'END:VCALENDAR'."\n" @@ -539,10 +539,10 @@ public function testRFC6321Section3Part6Part2() /** * Values, Calendar User Address. */ - public function testRFC6321Section3Part6Part3() + public function testRFC6321Section3Part6Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -554,7 +554,7 @@ public function testRFC6321Section3Part6Part3() XML -, + , 'BEGIN:VCALENDAR'."\n". 'ATTENDEE:mailto:cyrus@example.com'."\n". 'END:VCALENDAR'."\n" @@ -564,10 +564,10 @@ public function testRFC6321Section3Part6Part3() /** * Values, Date. */ - public function testRFC6321Section3Part6Part4() + public function testRFC6321Section3Part6Part4(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -579,7 +579,7 @@ public function testRFC6321Section3Part6Part4() XML -, + , 'BEGIN:VCALENDAR'."\n". 'DTSTART;VALUE=DATE:20110517'."\n". 'END:VCALENDAR'."\n" @@ -589,10 +589,10 @@ public function testRFC6321Section3Part6Part4() /** * Values, Date-Time. */ - public function testRFC6321Section3Part6Part5() + public function testRFC6321Section3Part6Part5(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -604,7 +604,7 @@ public function testRFC6321Section3Part6Part5() XML -, + , 'BEGIN:VCALENDAR'."\n". 'DTSTART:20110517T120000'."\n". 'END:VCALENDAR'."\n" @@ -614,10 +614,10 @@ public function testRFC6321Section3Part6Part5() /** * Values, Duration. */ - public function testRFC6321Section3Part6Part6() + public function testRFC6321Section3Part6Part6(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -629,7 +629,7 @@ public function testRFC6321Section3Part6Part6() XML -, + , 'BEGIN:VCALENDAR'."\n". 'DURATION:P1D'."\n". 'END:VCALENDAR'."\n" @@ -639,7 +639,7 @@ public function testRFC6321Section3Part6Part6() /** * Values, Float. */ - public function testRFC6321Section3Part6Part7() + public function testRFC6321Section3Part6Part7(): void { // GEO uses with a positive and a non-negative numbers. $this->testRFC6321Section3Part4Part1Part2(); @@ -648,10 +648,10 @@ public function testRFC6321Section3Part6Part7() /** * Values, Integer. */ - public function testRFC6321Section3Part6Part8() + public function testRFC6321Section3Part6Part8(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -663,14 +663,14 @@ public function testRFC6321Section3Part6Part8() XML -, + , 'BEGIN:VCALENDAR'."\n". 'FOO:42'."\n". 'END:VCALENDAR'."\n" ); - $this->assertXMLEqualsToMimeDir( -<< @@ -682,7 +682,7 @@ public function testRFC6321Section3Part6Part8() XML -, + , 'BEGIN:VCALENDAR'."\n". 'FOO:-42'."\n". 'END:VCALENDAR'."\n" @@ -692,10 +692,10 @@ public function testRFC6321Section3Part6Part8() /** * Values, Period of Time. */ - public function testRFC6321Section3Part6Part9() + public function testRFC6321Section3Part6Part9(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -710,14 +710,14 @@ public function testRFC6321Section3Part6Part9() XML -, + , 'BEGIN:VCALENDAR'."\n". 'FREEBUSY:20110517T120000/P1H'."\n". 'END:VCALENDAR'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -732,7 +732,7 @@ public function testRFC6321Section3Part6Part9() XML -, + , 'BEGIN:VCALENDAR'."\n". 'FREEBUSY:20110517T120000/20120517T120000'."\n". 'END:VCALENDAR'."\n" @@ -742,10 +742,10 @@ public function testRFC6321Section3Part6Part9() /** * Values, Recurrence Rule. */ - public function testRFC6321Section3Part6Part10() + public function testRFC6321Section3Part6Part10(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -762,7 +762,7 @@ public function testRFC6321Section3Part6Part10() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RRULE:FREQ=YEARLY;COUNT=5;BYDAY=-1SU;BYMONTH=10'."\n". 'END:VCALENDAR'."\n" @@ -772,10 +772,10 @@ public function testRFC6321Section3Part6Part10() /** * Values, Text. */ - public function testRFC6321Section3Part6Part11() + public function testRFC6321Section3Part6Part11(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -787,7 +787,7 @@ public function testRFC6321Section3Part6Part11() XML -, + , 'BEGIN:VCALENDAR'."\n". 'CALSCALE:GREGORIAN'."\n". 'END:VCALENDAR'."\n" @@ -797,10 +797,10 @@ public function testRFC6321Section3Part6Part11() /** * Values, Time. */ - public function testRFC6321Section3Part6Part12() + public function testRFC6321Section3Part6Part12(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -812,7 +812,7 @@ public function testRFC6321Section3Part6Part12() XML -, + , 'BEGIN:VCALENDAR'."\n". 'FOO:120000'."\n". 'END:VCALENDAR'."\n" @@ -822,10 +822,10 @@ public function testRFC6321Section3Part6Part12() /** * Values, URI. */ - public function testRFC6321Section3Part6Part13() + public function testRFC6321Section3Part6Part13(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -837,7 +837,7 @@ public function testRFC6321Section3Part6Part13() XML -, + , 'BEGIN:VCALENDAR'."\n". 'ATTACH:http://calendar.example.com'."\n". 'END:VCALENDAR'."\n" @@ -847,11 +847,11 @@ public function testRFC6321Section3Part6Part13() /** * Values, UTC Offset. */ - public function testRFC6321Section3Part6Part14() + public function testRFC6321Section3Part6Part14(): void { // Example 1 of RFC5545, Section 3.3.14. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -863,15 +863,15 @@ public function testRFC6321Section3Part6Part14() XML -, + , 'BEGIN:VCALENDAR'."\n". 'TZOFFSETFROM:-0500'."\n". 'END:VCALENDAR'."\n" ); // Example 2 of RFC5545, Section 3.3.14. - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -883,7 +883,7 @@ public function testRFC6321Section3Part6Part14() XML -, + , 'BEGIN:VCALENDAR'."\n". 'TZOFFSETFROM:+0100'."\n". 'END:VCALENDAR'."\n" @@ -893,10 +893,10 @@ public function testRFC6321Section3Part6Part14() /** * Handling Unrecognized Properties or Parameters. */ - public function testRFC6321Section5() + public function testRFC6321Section5(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -908,14 +908,14 @@ public function testRFC6321Section5() XML -, + , 'BEGIN:VCALENDAR'."\n". 'X-PROPERTY:20110512T120000Z'."\n". 'END:VCALENDAR'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -932,17 +932,17 @@ public function testRFC6321Section5() XML -, + , 'BEGIN:VCALENDAR'."\n". 'DTSTART;X-PARAM=PT30M:20110512T130000Z'."\n". 'END:VCALENDAR'."\n" ); } - public function testRDateWithDateTime() + public function testRDateWithDateTime(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -954,14 +954,14 @@ public function testRDateWithDateTime() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RDATE:20080205T191224Z'."\n". 'END:VCALENDAR'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -974,17 +974,17 @@ public function testRDateWithDateTime() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RDATE:20080205T191224Z,20090205T191224Z'."\n". 'END:VCALENDAR'."\n" ); } - public function testRDateWithDate() + public function testRDateWithDate(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -996,14 +996,14 @@ public function testRDateWithDate() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RDATE:20081006'."\n". 'END:VCALENDAR'."\n" ); - $this->assertXMLEqualsToMimeDir( -<< @@ -1017,17 +1017,17 @@ public function testRDateWithDate() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RDATE:20081006,20091006,20101006'."\n". 'END:VCALENDAR'."\n" ); } - public function testRDateWithPeriod() + public function testRDateWithPeriod(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1047,14 +1047,14 @@ public function testRDateWithPeriod() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RDATE;TZID=US/Eastern;VALUE=PERIOD:20060102T150000/PT2H'."\n". 'END:VCALENDAR'."\n" ); - $this->assertXMLEqualsToMimeDir( -<< @@ -1078,7 +1078,7 @@ public function testRDateWithPeriod() XML -, + , 'BEGIN:VCALENDAR'."\n". 'RDATE;TZID=US/Eastern;VALUE=PERIOD:20060102T150000/PT2H,20080102T150000/PT1'."\n". ' H'."\n". @@ -1089,10 +1089,10 @@ public function testRDateWithPeriod() /** * Basic example. */ - public function testRFC6351Basic() + public function testRFC6351Basic(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1109,7 +1109,7 @@ public function testRFC6351Basic() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'FN:J. Doe'."\n". @@ -1121,10 +1121,10 @@ public function testRFC6351Basic() /** * Example 1. */ - public function testRFC6351Example1() + public function testRFC6351Example1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1150,7 +1150,7 @@ public function testRFC6351Example1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'FN:J. Doe'."\n". @@ -1165,10 +1165,10 @@ public function testRFC6351Example1() /** * Design Considerations. */ - public function testRFC6351Section5() + public function testRFC6351Section5(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -1184,15 +1184,15 @@ public function testRFC6351Section5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TEL;TYPE="voice,video":tel:+1-555-555-555'."\n". 'END:VCARD'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1208,7 +1208,7 @@ public function testRFC6351Section5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TEL;TYPE="voice,video":tel:+1-555-555-555'."\n". @@ -1219,10 +1219,10 @@ public function testRFC6351Section5() /** * Design Considerations. */ - public function testRFC6351Section5Group() + public function testRFC6351Section5Group(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1245,7 +1245,7 @@ public function testRFC6351Section5Group() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TEL:tel:+1-555-555-556'."\n". @@ -1259,10 +1259,10 @@ public function testRFC6351Section5Group() /** * Extensibility. */ - public function testRFC6351Section5Part1NoNamespace() + public function testRFC6351Section5Part1NoNamespace(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -1277,7 +1277,7 @@ public function testRFC6351Section5Part1NoNamespace() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'X-MY-PROP;PREF=1:value goes here'."\n". @@ -1288,10 +1288,10 @@ public function testRFC6351Section5Part1NoNamespace() /** * Section 4.3.1 of Relax NG Schema: value-date. */ - public function testRFC6351ValueDateWithYearMonthDay() + public function testRFC6351ValueDateWithYearMonthDay(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1301,7 +1301,7 @@ public function testRFC6351ValueDateWithYearMonthDay() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:20150128'."\n". @@ -1312,10 +1312,10 @@ public function testRFC6351ValueDateWithYearMonthDay() /** * Section 4.3.1 of Relax NG Schema: value-date. */ - public function testRFC6351ValueDateWithYearMonth() + public function testRFC6351ValueDateWithYearMonth(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1325,7 +1325,7 @@ public function testRFC6351ValueDateWithYearMonth() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:2015-01'."\n". @@ -1336,10 +1336,10 @@ public function testRFC6351ValueDateWithYearMonth() /** * Section 4.3.1 of Relax NG Schema: value-date. */ - public function testRFC6351ValueDateWithMonth() + public function testRFC6351ValueDateWithMonth(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1349,7 +1349,7 @@ public function testRFC6351ValueDateWithMonth() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:--01'."\n". @@ -1360,10 +1360,10 @@ public function testRFC6351ValueDateWithMonth() /** * Section 4.3.1 of Relax NG Schema: value-date. */ - public function testRFC6351ValueDateWithMonthDay() + public function testRFC6351ValueDateWithMonthDay(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1373,7 +1373,7 @@ public function testRFC6351ValueDateWithMonthDay() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:--0128'."\n". @@ -1384,10 +1384,10 @@ public function testRFC6351ValueDateWithMonthDay() /** * Section 4.3.1 of Relax NG Schema: value-date. */ - public function testRFC6351ValueDateWithDay() + public function testRFC6351ValueDateWithDay(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1397,7 +1397,7 @@ public function testRFC6351ValueDateWithDay() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:---28'."\n". @@ -1408,10 +1408,10 @@ public function testRFC6351ValueDateWithDay() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithHour() + public function testRFC6351ValueTimeWithHour(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1421,7 +1421,7 @@ public function testRFC6351ValueTimeWithHour() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:13'."\n". @@ -1432,10 +1432,10 @@ public function testRFC6351ValueTimeWithHour() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithHourMinute() + public function testRFC6351ValueTimeWithHourMinute(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1445,7 +1445,7 @@ public function testRFC6351ValueTimeWithHourMinute() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:1353'."\n". @@ -1456,10 +1456,10 @@ public function testRFC6351ValueTimeWithHourMinute() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithHourMinuteSecond() + public function testRFC6351ValueTimeWithHourMinuteSecond(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1469,7 +1469,7 @@ public function testRFC6351ValueTimeWithHourMinuteSecond() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:135301'."\n". @@ -1480,10 +1480,10 @@ public function testRFC6351ValueTimeWithHourMinuteSecond() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithMinute() + public function testRFC6351ValueTimeWithMinute(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1493,7 +1493,7 @@ public function testRFC6351ValueTimeWithMinute() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:-53'."\n". @@ -1504,10 +1504,10 @@ public function testRFC6351ValueTimeWithMinute() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithMinuteSecond() + public function testRFC6351ValueTimeWithMinuteSecond(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1517,7 +1517,7 @@ public function testRFC6351ValueTimeWithMinuteSecond() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:-5301'."\n". @@ -1528,9 +1528,9 @@ public function testRFC6351ValueTimeWithMinuteSecond() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithSecond() + public function testRFC6351ValueTimeWithSecond(): void { - $this->assertTrue(true); + self::assertTrue(true); /* * According to the Relax NG Schema, there is a conflict between @@ -1538,7 +1538,7 @@ public function testRFC6351ValueTimeWithSecond() * value-date because of the higher priority set in * value-date-and-or-time. So we basically skip this test. * - $this->assertXMLReflexivelyEqualsToMimeDir( + self::assertXMLReflexivelyEqualsToMimeDir( << @@ -1561,10 +1561,10 @@ public function testRFC6351ValueTimeWithSecond() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithSecondZ() + public function testRFC6351ValueTimeWithSecondZ(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1574,7 +1574,7 @@ public function testRFC6351ValueTimeWithSecondZ() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:--01Z'."\n". @@ -1585,10 +1585,10 @@ public function testRFC6351ValueTimeWithSecondZ() /** * Section 4.3.2 of Relax NG Schema: value-time. */ - public function testRFC6351ValueTimeWithSecondTZ() + public function testRFC6351ValueTimeWithSecondTZ(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1598,7 +1598,7 @@ public function testRFC6351ValueTimeWithSecondTZ() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:--01+1234'."\n". @@ -1609,10 +1609,10 @@ public function testRFC6351ValueTimeWithSecondTZ() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithYearMonthDayHour() + public function testRFC6351ValueDateTimeWithYearMonthDayHour(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1622,7 +1622,7 @@ public function testRFC6351ValueDateTimeWithYearMonthDayHour() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:20150128T13'."\n". @@ -1633,10 +1633,10 @@ public function testRFC6351ValueDateTimeWithYearMonthDayHour() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithMonthDayHour() + public function testRFC6351ValueDateTimeWithMonthDayHour(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1646,7 +1646,7 @@ public function testRFC6351ValueDateTimeWithMonthDayHour() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:--0128T13'."\n". @@ -1657,10 +1657,10 @@ public function testRFC6351ValueDateTimeWithMonthDayHour() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithDayHour() + public function testRFC6351ValueDateTimeWithDayHour(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1670,7 +1670,7 @@ public function testRFC6351ValueDateTimeWithDayHour() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:---28T13'."\n". @@ -1681,10 +1681,10 @@ public function testRFC6351ValueDateTimeWithDayHour() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithDayHourMinute() + public function testRFC6351ValueDateTimeWithDayHourMinute(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1694,7 +1694,7 @@ public function testRFC6351ValueDateTimeWithDayHourMinute() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:---28T1353'."\n". @@ -1705,10 +1705,10 @@ public function testRFC6351ValueDateTimeWithDayHourMinute() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithDayHourMinuteSecond() + public function testRFC6351ValueDateTimeWithDayHourMinuteSecond(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1718,7 +1718,7 @@ public function testRFC6351ValueDateTimeWithDayHourMinuteSecond() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:---28T135301'."\n". @@ -1729,10 +1729,10 @@ public function testRFC6351ValueDateTimeWithDayHourMinuteSecond() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithDayHourZ() + public function testRFC6351ValueDateTimeWithDayHourZ(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1742,7 +1742,7 @@ public function testRFC6351ValueDateTimeWithDayHourZ() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:---28T13Z'."\n". @@ -1753,10 +1753,10 @@ public function testRFC6351ValueDateTimeWithDayHourZ() /** * Section 4.3.3 of Relax NG Schema: value-date-time. */ - public function testRFC6351ValueDateTimeWithDayHourTZ() + public function testRFC6351ValueDateTimeWithDayHourTZ(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1766,7 +1766,7 @@ public function testRFC6351ValueDateTimeWithDayHourTZ() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:---28T13+1234'."\n". @@ -1777,10 +1777,10 @@ public function testRFC6351ValueDateTimeWithDayHourTZ() /** * Property: SOURCE. */ - public function testRFC6350Section6Part1Part3() + public function testRFC6350Section6Part1Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1790,7 +1790,7 @@ public function testRFC6350Section6Part1Part3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'SOURCE:ldap://ldap.example.com/cn=Babs%20Jensen\,%20o=Babsco\,%20c=US'."\n". @@ -1801,10 +1801,10 @@ public function testRFC6350Section6Part1Part3() /** * Property: KIND. */ - public function testRFC6350Section6Part1Part4() + public function testRFC6350Section6Part1Part4(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1814,7 +1814,7 @@ public function testRFC6350Section6Part1Part4() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'KIND:individual'."\n". @@ -1825,10 +1825,10 @@ public function testRFC6350Section6Part1Part4() /** * Property: FN. */ - public function testRFC6350Section6Part2Part1() + public function testRFC6350Section6Part2Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1838,7 +1838,7 @@ public function testRFC6350Section6Part2Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'FN:Mr. John Q. Public\, Esq.'."\n". @@ -1849,10 +1849,10 @@ public function testRFC6350Section6Part2Part1() /** * Property: N. */ - public function testRFC6350Section6Part2Part2() + public function testRFC6350Section6Part2Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1866,7 +1866,7 @@ public function testRFC6350Section6Part2Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'N:Stevenson;John;Philip\,Paul;Dr.;Jr.\,M.D.\,A.C.P.'."\n". @@ -1877,10 +1877,10 @@ public function testRFC6350Section6Part2Part2() /** * Property: NICKNAME. */ - public function testRFC6350Section6Part2Part3() + public function testRFC6350Section6Part2Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1891,7 +1891,7 @@ public function testRFC6350Section6Part2Part3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'NICKNAME:Jim,Jimmie'."\n". @@ -1902,10 +1902,10 @@ public function testRFC6350Section6Part2Part3() /** * Property: PHOTO. */ - public function testRFC6350Section6Part2Part4() + public function testRFC6350Section6Part2Part4(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1915,7 +1915,7 @@ public function testRFC6350Section6Part2Part4() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'PHOTO:http://www.example.com/pub/photos/jqpublic.gif'."\n". @@ -1923,10 +1923,10 @@ public function testRFC6350Section6Part2Part4() ); } - public function testRFC6350Section6Part2Part5() + public function testRFC6350Section6Part2Part5(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1936,7 +1936,7 @@ public function testRFC6350Section6Part2Part5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'BDAY:19531015T231000Z'."\n". @@ -1944,10 +1944,10 @@ public function testRFC6350Section6Part2Part5() ); } - public function testRFC6350Section6Part2Part6() + public function testRFC6350Section6Part2Part6(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1957,7 +1957,7 @@ public function testRFC6350Section6Part2Part6() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'ANNIVERSARY:19960415'."\n". @@ -1968,10 +1968,10 @@ public function testRFC6350Section6Part2Part6() /** * Property: GENDER. */ - public function testRFC6350Section6Part2Part7() + public function testRFC6350Section6Part2Part7(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -1982,7 +1982,7 @@ public function testRFC6350Section6Part2Part7() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'GENDER:Jim;Jimmie'."\n". @@ -1993,10 +1993,10 @@ public function testRFC6350Section6Part2Part7() /** * Property: ADR. */ - public function testRFC6350Section6Part3Part1() + public function testRFC6350Section6Part3Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2012,7 +2012,7 @@ public function testRFC6350Section6Part3Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'ADR:;;123 Main Street;Any Town;CA;91921-1234;U.S.A.'."\n". @@ -2023,7 +2023,7 @@ public function testRFC6350Section6Part3Part1() /** * Property: TEL. */ - public function testRFC6350Section6Part4Part1() + public function testRFC6350Section6Part4Part1(): void { /* * Quoting RFC: @@ -2035,8 +2035,8 @@ public function testRFC6350Section6Part4Part1() * So first, we test xCard/URI to vCard/URI. * Then, we test xCard/TEXT to vCard/TEXT to xCard/TEXT. */ - $this->assertXMLEqualsToMimeDir( -<< @@ -2051,15 +2051,15 @@ public function testRFC6350Section6Part4Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TEL;TYPE=home:tel:+33-01-23-45-67'."\n". 'END:VCARD'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2074,7 +2074,7 @@ public function testRFC6350Section6Part4Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TEL;TYPE=home:tel:+33-01-23-45-67'."\n". @@ -2085,10 +2085,10 @@ public function testRFC6350Section6Part4Part1() /** * Property: EMAIL. */ - public function testRFC6350Section6Part4Part2() + public function testRFC6350Section6Part4Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2103,7 +2103,7 @@ public function testRFC6350Section6Part4Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'EMAIL;TYPE=work:jqpublic@xyz.example.com'."\n". @@ -2114,10 +2114,10 @@ public function testRFC6350Section6Part4Part2() /** * Property: IMPP. */ - public function testRFC6350Section6Part4Part3() + public function testRFC6350Section6Part4Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2132,7 +2132,7 @@ public function testRFC6350Section6Part4Part3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'IMPP;PREF=1:xmpp:alice@example.com'."\n". @@ -2143,10 +2143,10 @@ public function testRFC6350Section6Part4Part3() /** * Property: LANG. */ - public function testRFC6350Section6Part4Part4() + public function testRFC6350Section6Part4Part4(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2164,7 +2164,7 @@ public function testRFC6350Section6Part4Part4() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'LANG;TYPE=work;PREF=2:en'."\n". @@ -2175,10 +2175,10 @@ public function testRFC6350Section6Part4Part4() /** * Property: TZ. */ - public function testRFC6350Section6Part5Part1() + public function testRFC6350Section6Part5Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2188,7 +2188,7 @@ public function testRFC6350Section6Part5Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TZ:Raleigh/North America'."\n". @@ -2199,10 +2199,10 @@ public function testRFC6350Section6Part5Part1() /** * Property: GEO. */ - public function testRFC6350Section6Part5Part2() + public function testRFC6350Section6Part5Part2(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -2212,15 +2212,15 @@ public function testRFC6350Section6Part5Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'GEO:geo:37.386013\,-122.082932'."\n". 'END:VCARD'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2230,7 +2230,7 @@ public function testRFC6350Section6Part5Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'GEO:geo:37.386013\,-122.082932'."\n". @@ -2241,10 +2241,10 @@ public function testRFC6350Section6Part5Part2() /** * Property: TITLE. */ - public function testRFC6350Section6Part6Part1() + public function testRFC6350Section6Part6Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2254,7 +2254,7 @@ public function testRFC6350Section6Part6Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'TITLE:Research Scientist'."\n". @@ -2265,10 +2265,10 @@ public function testRFC6350Section6Part6Part1() /** * Property: ROLE. */ - public function testRFC6350Section6Part6Part2() + public function testRFC6350Section6Part6Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2278,7 +2278,7 @@ public function testRFC6350Section6Part6Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'ROLE:Project Leader'."\n". @@ -2289,10 +2289,10 @@ public function testRFC6350Section6Part6Part2() /** * Property: LOGO. */ - public function testRFC6350Section6Part6Part3() + public function testRFC6350Section6Part6Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2302,7 +2302,7 @@ public function testRFC6350Section6Part6Part3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'LOGO:http://www.example.com/pub/logos/abccorp.jpg'."\n". @@ -2313,10 +2313,10 @@ public function testRFC6350Section6Part6Part3() /** * Property: ORG. */ - public function testRFC6350Section6Part6Part4() + public function testRFC6350Section6Part6Part4(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2328,7 +2328,7 @@ public function testRFC6350Section6Part6Part4() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'ORG:ABC\, Inc.;North American Division;Marketing'."\n". @@ -2339,10 +2339,10 @@ public function testRFC6350Section6Part6Part4() /** * Property: MEMBER. */ - public function testRFC6350Section6Part6Part5() + public function testRFC6350Section6Part6Part5(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2352,15 +2352,15 @@ public function testRFC6350Section6Part6Part5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'MEMBER:urn:uuid:03a0e51f-d1aa-4385-8a53-e29025acd8af'."\n". 'END:VCARD'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2379,7 +2379,7 @@ public function testRFC6350Section6Part6Part5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'MEMBER:mailto:subscriber1@example.com'."\n". @@ -2393,10 +2393,10 @@ public function testRFC6350Section6Part6Part5() /** * Property: RELATED. */ - public function testRFC6350Section6Part6Part6() + public function testRFC6350Section6Part6Part6(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2411,7 +2411,7 @@ public function testRFC6350Section6Part6Part6() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'RELATED;TYPE=friend:urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'."\n". @@ -2422,10 +2422,10 @@ public function testRFC6350Section6Part6Part6() /** * Property: CATEGORIES. */ - public function testRFC6350Section6Part7Part1() + public function testRFC6350Section6Part7Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2438,7 +2438,7 @@ public function testRFC6350Section6Part7Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'CATEGORIES:INTERNET,IETF,INDUSTRY,INFORMATION TECHNOLOGY'."\n". @@ -2449,10 +2449,10 @@ public function testRFC6350Section6Part7Part1() /** * Property: NOTE. */ - public function testRFC6350Section6Part7Part2() + public function testRFC6350Section6Part7Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2462,7 +2462,7 @@ public function testRFC6350Section6Part7Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'NOTE:Foo\, bar'."\n". @@ -2473,10 +2473,10 @@ public function testRFC6350Section6Part7Part2() /** * Property: PRODID. */ - public function testRFC6350Section6Part7Part3() + public function testRFC6350Section6Part7Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2486,7 +2486,7 @@ public function testRFC6350Section6Part7Part3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'PRODID:-//ONLINE DIRECTORY//NONSGML Version 1//EN'."\n". @@ -2494,10 +2494,10 @@ public function testRFC6350Section6Part7Part3() ); } - public function testRFC6350Section6Part7Part4() + public function testRFC6350Section6Part7Part4(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2507,7 +2507,7 @@ public function testRFC6350Section6Part7Part4() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'REV:19951031T222710Z'."\n". @@ -2518,10 +2518,10 @@ public function testRFC6350Section6Part7Part4() /** * Property: SOUND. */ - public function testRFC6350Section6Part7Part5() + public function testRFC6350Section6Part7Part5(): void { - $this->assertXMLEqualsToMimeDir( -<< @@ -2531,15 +2531,15 @@ public function testRFC6350Section6Part7Part5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'SOUND:CID:JOHNQPUBLIC.part8.19960229T080000.xyzMail@example.com'."\n". 'END:VCARD'."\n" ); - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2549,7 +2549,7 @@ public function testRFC6350Section6Part7Part5() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'SOUND:CID:JOHNQPUBLIC.part8.19960229T080000.xyzMail@example.com'."\n". @@ -2560,10 +2560,10 @@ public function testRFC6350Section6Part7Part5() /** * Property: UID. */ - public function testRFC6350Section6Part7Part6() + public function testRFC6350Section6Part7Part6(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2573,7 +2573,7 @@ public function testRFC6350Section6Part7Part6() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'UID:urn:uuid:f81d4fae-7dec-11d0-a765-00a0c91e6bf6'."\n". @@ -2584,10 +2584,10 @@ public function testRFC6350Section6Part7Part6() /** * Property: CLIENTPIDMAP. */ - public function testRFC6350Section6Part7Part7() + public function testRFC6350Section6Part7Part7(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2598,7 +2598,7 @@ public function testRFC6350Section6Part7Part7() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'CLIENTPIDMAP:1;urn:uuid:3df403f4-5924-4bb7-b077-3c711d9eb34b'."\n". @@ -2609,10 +2609,10 @@ public function testRFC6350Section6Part7Part7() /** * Property: URL. */ - public function testRFC6350Section6Part7Part8() + public function testRFC6350Section6Part7Part8(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2622,7 +2622,7 @@ public function testRFC6350Section6Part7Part8() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'URL:http://example.org/restaurant.french/~chezchic.html'."\n". @@ -2633,16 +2633,16 @@ public function testRFC6350Section6Part7Part8() /** * Property: VERSION. */ - public function testRFC6350Section6Part7Part9() + public function testRFC6350Section6Part7Part9(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'END:VCARD'."\n" @@ -2652,10 +2652,10 @@ public function testRFC6350Section6Part7Part9() /** * Property: KEY. */ - public function testRFC6350Section6Part8Part1() + public function testRFC6350Section6Part8Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2670,7 +2670,7 @@ public function testRFC6350Section6Part8Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'KEY;MEDIATYPE=application/pgp-keys:ftp://example.com/keys/jdoe'."\n". @@ -2681,10 +2681,10 @@ public function testRFC6350Section6Part8Part1() /** * Property: FBURL. */ - public function testRFC6350Section6Part9Part1() + public function testRFC6350Section6Part9Part1(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2699,7 +2699,7 @@ public function testRFC6350Section6Part9Part1() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'FBURL;PREF=1:http://www.example.com/busy/janedoe'."\n". @@ -2710,10 +2710,10 @@ public function testRFC6350Section6Part9Part1() /** * Property: CALADRURI. */ - public function testRFC6350Section6Part9Part2() + public function testRFC6350Section6Part9Part2(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2723,7 +2723,7 @@ public function testRFC6350Section6Part9Part2() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'CALADRURI:http://example.com/calendar/jdoe'."\n". @@ -2734,10 +2734,10 @@ public function testRFC6350Section6Part9Part2() /** * Property: CALURI. */ - public function testRFC6350Section6Part9Part3() + public function testRFC6350Section6Part9Part3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2752,7 +2752,7 @@ public function testRFC6350Section6Part9Part3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'CALURI;PREF=1:http://cal.example.com/calA'."\n". @@ -2763,10 +2763,10 @@ public function testRFC6350Section6Part9Part3() /** * Property: CAPURI. */ - public function testRFC6350SectionAPart3() + public function testRFC6350SectionAPart3(): void { - $this->assertXMLReflexivelyEqualsToMimeDir( -<< @@ -2776,7 +2776,7 @@ public function testRFC6350SectionAPart3() XML -, + , 'BEGIN:VCARD'."\n". 'VERSION:4.0'."\n". 'CAPURI:http://cap.example.com/capA'."\n". @@ -2788,21 +2788,21 @@ public function testRFC6350SectionAPart3() * Check this equality: * XML -> object model -> MIME Dir. */ - protected function assertXMLEqualsToMimeDir($xml, $mimedir) + protected function assertXMLEqualsToMimeDir(string $xml, string $mimedir): void { $component = VObject\Reader::readXML($xml); - $this->assertVObjectEqualsVObject($mimedir, $component); + self::assertVObjectEqualsVObject($mimedir, $component); } /** * Check this (reflexive) equality: * XML -> object model -> MIME Dir -> object model -> XML. */ - protected function assertXMLReflexivelyEqualsToMimeDir($xml, $mimedir) + protected function assertXMLReflexivelyEqualsToMimeDir(string $xml, string $mimedir): void { - $this->assertXMLEqualsToMimeDir($xml, $mimedir); + self::assertXMLEqualsToMimeDir($xml, $mimedir); $component = VObject\Reader::read($mimedir); - $this->assertXmlStringEqualsXmlString($xml, VObject\Writer::writeXML($component)); + self::assertXmlStringEqualsXmlString($xml, VObject\Writer::writeXML($component)); } } diff --git a/tests/VObject/Property/BinaryTest.php b/tests/VObject/Property/BinaryTest.php index b1c2dada7..8d2736573 100644 --- a/tests/VObject/Property/BinaryTest.php +++ b/tests/VObject/Property/BinaryTest.php @@ -7,7 +7,7 @@ class BinaryTest extends TestCase { - public function testMimeDir() + public function testMimeDir(): void { $this->expectException(\InvalidArgumentException::class); $vcard = new VObject\Component\VCard(['VERSION' => '3.0']); diff --git a/tests/VObject/Property/BooleanTest.php b/tests/VObject/Property/BooleanTest.php index ad2ccbcd7..82684dd71 100644 --- a/tests/VObject/Property/BooleanTest.php +++ b/tests/VObject/Property/BooleanTest.php @@ -7,15 +7,18 @@ class BooleanTest extends TestCase { - public function testMimeDir() + /** + * @throws VObject\ParseException + */ + public function testMimeDir(): void { $input = "BEGIN:VCARD\r\nX-AWESOME;VALUE=BOOLEAN:TRUE\r\nX-SUCKS;VALUE=BOOLEAN:FALSE\r\nEND:VCARD\r\n"; $vcard = VObject\Reader::read($input); - $this->assertTrue($vcard->{'X-AWESOME'}->getValue()); - $this->assertFalse($vcard->{'X-SUCKS'}->getValue()); + self::assertTrue($vcard->{'X-AWESOME'}->getValue()); + self::assertFalse($vcard->{'X-SUCKS'}->getValue()); - $this->assertEquals('BOOLEAN', $vcard->{'X-AWESOME'}->getValueType()); - $this->assertEquals($input, $vcard->serialize()); + self::assertEquals('BOOLEAN', $vcard->{'X-AWESOME'}->getValueType()); + self::assertEquals($input, $vcard->serialize()); } } diff --git a/tests/VObject/Property/CompoundTest.php b/tests/VObject/Property/CompoundTest.php index bfa1ed64b..073d9627a 100644 --- a/tests/VObject/Property/CompoundTest.php +++ b/tests/VObject/Property/CompoundTest.php @@ -7,7 +7,7 @@ class CompoundTest extends TestCase { - public function testSetParts() + public function testSetParts(): void { $arr = [ 'ABC, Inc.', @@ -19,13 +19,13 @@ public function testSetParts() $elem = $vcard->createProperty('ORG'); $elem->setParts($arr); - $this->assertEquals('ABC\, Inc.;North American Division;Marketing\;Sales', $elem->getValue()); - $this->assertEquals(3, count($elem->getParts())); + self::assertEquals('ABC\, Inc.;North American Division;Marketing\;Sales', $elem->getValue()); + self::assertCount(3, $elem->getParts()); $parts = $elem->getParts(); - $this->assertEquals('Marketing;Sales', $parts[2]); + self::assertEquals('Marketing;Sales', $parts[2]); } - public function testGetParts() + public function testGetParts(): void { $str = 'ABC\, Inc.;North American Division;Marketing\;Sales'; @@ -33,16 +33,16 @@ public function testGetParts() $elem = $vcard->createProperty('ORG'); $elem->setRawMimeDirValue($str); - $this->assertEquals(3, count($elem->getParts())); + self::assertCount(3, $elem->getParts()); $parts = $elem->getParts(); - $this->assertEquals('Marketing;Sales', $parts[2]); + self::assertEquals('Marketing;Sales', $parts[2]); } - public function testGetPartsNull() + public function testGetPartsNull(): void { $vcard = new VCard(); $elem = $vcard->createProperty('ORG', null); - $this->assertEquals(0, count($elem->getParts())); + self::assertCount(0, $elem->getParts()); } } diff --git a/tests/VObject/Property/FloatTest.php b/tests/VObject/Property/FloatTest.php index 0ba02470e..b5fee5d75 100644 --- a/tests/VObject/Property/FloatTest.php +++ b/tests/VObject/Property/FloatTest.php @@ -7,21 +7,21 @@ class FloatTest extends TestCase { - public function testMimeDir() + public function testMimeDir(): void { $input = "BEGIN:VCARD\r\nVERSION:4.0\r\nX-FLOAT;VALUE=FLOAT:0.234;1.245\r\nEND:VCARD\r\n"; $mimeDir = new VObject\Parser\MimeDir($input); $result = $mimeDir->parse($input); - $this->assertInstanceOf(FloatValue::class, $result->{'X-FLOAT'}); + self::assertInstanceOf(FloatValue::class, $result->{'X-FLOAT'}); - $this->assertEquals([ + self::assertEquals([ 0.234, 1.245, ], $result->{'X-FLOAT'}->getParts()); - $this->assertEquals( + self::assertEquals( $input, $result->serialize() ); diff --git a/tests/VObject/Property/ICalendar/CalAddressTest.php b/tests/VObject/Property/ICalendar/CalAddressTest.php index a907daf5c..b774f4fbc 100644 --- a/tests/VObject/Property/ICalendar/CalAddressTest.php +++ b/tests/VObject/Property/ICalendar/CalAddressTest.php @@ -9,22 +9,24 @@ class CalAddressTest extends TestCase /** * @dataProvider values */ - public function testGetNormalizedValue($expected, $input) + public function testGetNormalizedValue(string $expected, string $input): void { $vobj = new \Sabre\VObject\Component\VCalendar(); $property = $vobj->add('ATTENDEE', $input); - $this->assertEquals( + self::assertEquals( $expected, $property->getNormalizedValue() ); } - public function values() + public function values(): array { return [ ['mailto:a@b.com', 'mailto:a@b.com'], ['mailto:a@b.com', 'MAILTO:a@b.com'], + ['mailto:a@b.com', 'mailto:A@B.COM'], + ['mailto:a@b.com', 'MAILTO:A@B.COM'], ['/foo/bar', '/foo/bar'], ]; } diff --git a/tests/VObject/Property/ICalendar/DateTimeTest.php b/tests/VObject/Property/ICalendar/DateTimeTest.php index aa584dba5..0da557b93 100644 --- a/tests/VObject/Property/ICalendar/DateTimeTest.php +++ b/tests/VObject/Property/ICalendar/DateTimeTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Property\ICalendar; -use InvalidArgumentException; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\InvalidDataException; @@ -16,7 +15,7 @@ public function setUp(): void $this->vcal = new VCalendar(); } - public function testSetDateTime() + public function testSetDateTime(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); @@ -25,29 +24,29 @@ public function testSetDateTime() $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); - $this->assertEquals('19850704T013000', (string) $elem); - $this->assertEquals('Europe/Amsterdam', (string) $elem['TZID']); - $this->assertNull($elem['VALUE']); + self::assertEquals('19850704T013000', (string) $elem); + self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertNull($elem['VALUE']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetDateTimeLOCAL() + public function testSetDateTimeLOCAL(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); $dt->setTimeZone($tz); $elem = $this->vcal->createProperty('DTSTART'); - $elem->setDateTime($dt, $isFloating = true); + $elem->setDateTime($dt, true); - $this->assertEquals('19850704T013000', (string) $elem); - $this->assertNull($elem['TZID']); + self::assertEquals('19850704T013000', (string) $elem); + self::assertNull($elem['TZID']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetDateTimeUTC() + public function testSetDateTimeUTC(): void { $tz = new \DateTimeZone('GMT'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); @@ -56,13 +55,13 @@ public function testSetDateTimeUTC() $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); - $this->assertEquals('19850704T013000Z', (string) $elem); - $this->assertNull($elem['TZID']); + self::assertEquals('19850704T013000Z', (string) $elem); + self::assertNull($elem['TZID']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetDateTimeFromUnixTimestamp() + public function testSetDateTimeFromUnixTimestamp(): void { // When initialized from a Unix timestamp, the timezone is set to "+00:00". $dt = new \DateTime('@489288600'); @@ -70,13 +69,13 @@ public function testSetDateTimeFromUnixTimestamp() $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); - $this->assertEquals('19850704T013000Z', (string) $elem); - $this->assertNull($elem['TZID']); + self::assertEquals('19850704T013000Z', (string) $elem); + self::assertNull($elem['TZID']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetDateTimeLOCALTZ() + public function testSetDateTimeLOCALTZ(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); @@ -85,13 +84,13 @@ public function testSetDateTimeLOCALTZ() $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); - $this->assertEquals('19850704T013000', (string) $elem); - $this->assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertEquals('19850704T013000', (string) $elem); + self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetDateTimeDATE() + public function testSetDateTimeDATE(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); @@ -101,14 +100,14 @@ public function testSetDateTimeDATE() $elem['VALUE'] = 'DATE'; $elem->setDateTime($dt); - $this->assertEquals('19850704', (string) $elem); - $this->assertNull($elem['TZID']); - $this->assertEquals('DATE', (string) $elem['VALUE']); + self::assertEquals('19850704', (string) $elem); + self::assertNull($elem['TZID']); + self::assertEquals('DATE', (string) $elem['VALUE']); - $this->assertFalse($elem->hasTime()); + self::assertFalse($elem->hasTime()); } - public function testSetValue() + public function testSetValue(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTime('1985-07-04 01:30:00', $tz); @@ -117,14 +116,14 @@ public function testSetValue() $elem = $this->vcal->createProperty('DTSTART'); $elem->setValue($dt); - $this->assertEquals('19850704T013000', (string) $elem); - $this->assertEquals('Europe/Amsterdam', (string) $elem['TZID']); - $this->assertNull($elem['VALUE']); + self::assertEquals('19850704T013000', (string) $elem); + self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertNull($elem['VALUE']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetValueArray() + public function testSetValueArray(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); @@ -135,14 +134,14 @@ public function testSetValueArray() $elem = $this->vcal->createProperty('DTSTART'); $elem->setValue([$dt1, $dt2]); - $this->assertEquals('19850704T013000,19850704T023000', (string) $elem); - $this->assertEquals('Europe/Amsterdam', (string) $elem['TZID']); - $this->assertNull($elem['VALUE']); + self::assertEquals('19850704T013000,19850704T023000', (string) $elem); + self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertNull($elem['VALUE']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetParts() + public function testSetParts(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt1 = new \DateTime('1985-07-04 01:30:00', $tz); @@ -153,14 +152,14 @@ public function testSetParts() $elem = $this->vcal->createProperty('DTSTART'); $elem->setParts([$dt1, $dt2]); - $this->assertEquals('19850704T013000,19850704T023000', (string) $elem); - $this->assertEquals('Europe/Amsterdam', (string) $elem['TZID']); - $this->assertNull($elem['VALUE']); + self::assertEquals('19850704T013000,19850704T023000', (string) $elem); + self::assertEquals('Europe/Amsterdam', (string) $elem['TZID']); + self::assertNull($elem['VALUE']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testSetPartsStrings() + public function testSetPartsStrings(): void { $dt1 = '19850704T013000Z'; $dt2 = '19850704T023000Z'; @@ -168,13 +167,13 @@ public function testSetPartsStrings() $elem = $this->vcal->createProperty('DTSTART'); $elem->setParts([$dt1, $dt2]); - $this->assertEquals('19850704T013000Z,19850704T023000Z', (string) $elem); - $this->assertNull($elem['VALUE']); + self::assertEquals('19850704T013000Z,19850704T023000Z', (string) $elem); + self::assertNull($elem['VALUE']); - $this->assertTrue($elem->hasTime()); + self::assertTrue($elem->hasTime()); } - public function testGetDateTimeCached() + public function testGetDateTimeCached(): void { $tz = new \DateTimeZone('Europe/Amsterdam'); $dt = new \DateTimeImmutable('1985-07-04 01:30:00', $tz); @@ -183,27 +182,27 @@ public function testGetDateTimeCached() $elem = $this->vcal->createProperty('DTSTART'); $elem->setDateTime($dt); - $this->assertEquals($elem->getDateTime(), $dt); + self::assertEquals($elem->getDateTime(), $dt); } - public function testGetDateTimeDateNULL() + public function testGetDateTimeDateNULL(): void { $elem = $this->vcal->createProperty('DTSTART'); $dt = $elem->getDateTime(); - $this->assertNull($dt); + self::assertNull($dt); } - public function testGetDateTimeDateDATE() + public function testGetDateTimeDateDATE(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704'); $dt = $elem->getDateTime(); - $this->assertInstanceOf('DateTimeImmutable', $dt); - $this->assertEquals('1985-07-04 00:00:00', $dt->format('Y-m-d H:i:s')); + self::assertInstanceOf('DateTimeImmutable', $dt); + self::assertEquals('1985-07-04 00:00:00', $dt->format('Y-m-d H:i:s')); } - public function testGetDateTimeDateDATEReferenceTimeZone() + public function testGetDateTimeDateDATEReferenceTimeZone(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704'); @@ -211,20 +210,20 @@ public function testGetDateTimeDateDATEReferenceTimeZone() $dt = $elem->getDateTime($tz); $dt = $dt->setTimeZone(new \DateTimeZone('UTC')); - $this->assertInstanceOf('DateTimeImmutable', $dt); - $this->assertEquals('1985-07-04 04:00:00', $dt->format('Y-m-d H:i:s')); + self::assertInstanceOf('DateTimeImmutable', $dt); + self::assertEquals('1985-07-04 04:00:00', $dt->format('Y-m-d H:i:s')); } - public function testGetDateTimeDateFloating() + public function testGetDateTimeDateFloating(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $dt = $elem->getDateTime(); - $this->assertInstanceOf('DateTimeImmutable', $dt); - $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); + self::assertInstanceOf('DateTimeImmutable', $dt); + self::assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); } - public function testGetDateTimeDateFloatingReferenceTimeZone() + public function testGetDateTimeDateFloatingReferenceTimeZone(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); @@ -232,40 +231,40 @@ public function testGetDateTimeDateFloatingReferenceTimeZone() $dt = $elem->getDateTime($tz); $dt = $dt->setTimeZone(new \DateTimeZone('UTC')); - $this->assertInstanceOf('DateTimeInterface', $dt); - $this->assertEquals('1985-07-04 05:30:00', $dt->format('Y-m-d H:i:s')); + self::assertInstanceOf('DateTimeInterface', $dt); + self::assertEquals('1985-07-04 05:30:00', $dt->format('Y-m-d H:i:s')); } - public function testGetDateTimeDateUTC() + public function testGetDateTimeDateUTC(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704T013000Z'); $dt = $elem->getDateTime(); - $this->assertInstanceOf('DateTimeImmutable', $dt); - $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); - $this->assertEquals('UTC', $dt->getTimeZone()->getName()); + self::assertInstanceOf('DateTimeImmutable', $dt); + self::assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); + self::assertEquals('UTC', $dt->getTimeZone()->getName()); } - public function testGetDateTimeDateLOCALTZ() + public function testGetDateTimeDateLOCALTZ(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $elem['TZID'] = 'Europe/Amsterdam'; $dt = $elem->getDateTime(); - $this->assertInstanceOf('DateTimeImmutable', $dt); - $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); - $this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); + self::assertInstanceOf('DateTimeImmutable', $dt); + self::assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); + self::assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); } - public function testGetDateTimeDateInvalid() + public function testGetDateTimeDateInvalid(): void { $this->expectException(InvalidDataException::class); $elem = $this->vcal->createProperty('DTSTART', 'bla'); - $dt = $elem->getDateTime(); + $elem->getDateTime(); } - public function testGetDateTimeWeirdTZ() + public function testGetDateTimeWeirdTZ(): void { $elem = $this->vcal->createProperty('DTSTART', '19850704T013000'); $elem['TZID'] = '/freeassociation.sourceforge.net/Tzfile/Europe/Amsterdam'; @@ -282,12 +281,12 @@ public function testGetDateTimeWeirdTZ() $dt = $elem->getDateTime(); - $this->assertInstanceOf('DateTimeImmutable', $dt); - $this->assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); - $this->assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); + self::assertInstanceOf('DateTimeImmutable', $dt); + self::assertEquals('1985-07-04 01:30:00', $dt->format('Y-m-d H:i:s')); + self::assertEquals('Europe/Amsterdam', $dt->getTimeZone()->getName()); } - public function testGetDateTimeBadTimeZone() + public function testGetDateTimeBadTimeZone(): void { $default = date_default_timezone_get(); date_default_timezone_set('Canada/Eastern'); @@ -306,31 +305,31 @@ public function testGetDateTimeBadTimeZone() $this->vcal->add($timezone); date_default_timezone_set($default); - $this->expectException(InvalidArgumentException::class); + $this->expectException(\InvalidArgumentException::class); $this->expectExceptionMessage('We were unable to determine the correct PHP timezone for tzid: Moon'); $elem->getDateTime(); } - public function testUpdateValueParameter() + public function testUpdateValueParameter(): void { $dtStart = $this->vcal->createProperty('DTSTART', new \DateTime('2013-06-07 15:05:00')); $dtStart['VALUE'] = 'DATE'; - $this->assertEquals("DTSTART;VALUE=DATE:20130607\r\n", $dtStart->serialize()); + self::assertEquals("DTSTART;VALUE=DATE:20130607\r\n", $dtStart->serialize()); } - public function testValidate() + public function testValidate(): void { $exDate = $this->vcal->createProperty('EXDATE', '-00011130T143000Z'); $messages = $exDate->validate(); - $this->assertEquals(1, count($messages)); - $this->assertEquals(3, $messages[0]['level']); + self::assertCount(1, $messages); + self::assertEquals(3, $messages[0]['level']); } /** * This issue was discovered on the sabredav mailing list. */ - public function testCreateDatePropertyThroughAdd() + public function testCreateDatePropertyThroughAdd(): void { $vcal = new VCalendar(); $vevent = $vcal->add('VEVENT'); @@ -341,6 +340,6 @@ public function testCreateDatePropertyThroughAdd() ['VALUE' => 'DATE'] ); - $this->assertEquals("DTSTART;VALUE=DATE:20140307\r\n", $dtstart->serialize()); + self::assertEquals("DTSTART;VALUE=DATE:20140307\r\n", $dtstart->serialize()); } } diff --git a/tests/VObject/Property/ICalendar/DurationTest.php b/tests/VObject/Property/ICalendar/DurationTest.php index 2003ad6d2..044f86279 100644 --- a/tests/VObject/Property/ICalendar/DurationTest.php +++ b/tests/VObject/Property/ICalendar/DurationTest.php @@ -7,12 +7,12 @@ class DurationTest extends TestCase { - public function testGetDateInterval() + public function testGetDateInterval(): void { $vcal = new VCalendar(); $event = $vcal->add('VEVENT', ['DURATION' => ['PT1H']]); - $this->assertEquals( + self::assertEquals( new \DateInterval('PT1H'), $event->{'DURATION'}->getDateInterval() ); diff --git a/tests/VObject/Property/ICalendar/RecurTest.php b/tests/VObject/Property/ICalendar/RecurTest.php index 3902a6e13..b2750f03b 100644 --- a/tests/VObject/Property/ICalendar/RecurTest.php +++ b/tests/VObject/Property/ICalendar/RecurTest.php @@ -11,20 +11,20 @@ class RecurTest extends TestCase { use \Sabre\VObject\PHPUnitAssertions; - public function testParts() + public function testParts(): void { $vcal = new VCalendar(); $recur = $vcal->add('RRULE', 'FREQ=Daily'); - $this->assertInstanceOf(Recur::class, $recur); + self::assertInstanceOf(Recur::class, $recur); - $this->assertEquals(['FREQ' => 'DAILY'], $recur->getParts()); + self::assertEquals(['FREQ' => 'DAILY'], $recur->getParts()); $recur->setParts(['freq' => 'MONTHLY']); - $this->assertEquals(['FREQ' => 'MONTHLY'], $recur->getParts()); + self::assertEquals(['FREQ' => 'MONTHLY'], $recur->getParts()); } - public function testSetValueBadVal() + public function testSetValueBadVal(): void { $this->expectException(\InvalidArgumentException::class); $vcal = new VCalendar(); @@ -32,15 +32,15 @@ public function testSetValueBadVal() $recur->setValue(new \Exception()); } - public function testSetValueWithCount() + public function testSetValueWithCount(): void { $vcal = new VCalendar(); $recur = $vcal->add('RRULE', 'FREQ=Daily'); $recur->setValue(['COUNT' => 3]); - $this->assertEquals($recur->getParts()['COUNT'], 3); + self::assertEquals(3, $recur->getParts()['COUNT']); } - public function testGetJSONWithCount() + public function testGetJSONWithCount(): void { $input = 'BEGIN:VCALENDAR BEGIN:VEVENT @@ -58,23 +58,23 @@ public function testGetJSONWithCount() $vcal = Reader::read($input); $rrule = $vcal->VEVENT->RRULE; $count = $rrule->getJsonValue()[0]['count']; - $this->assertTrue(is_int($count)); - $this->assertEquals(3, $count); + self::assertTrue(is_int($count)); + self::assertEquals(3, $count); } - public function testSetSubParts() + public function testSetSubParts(): void { $vcal = new VCalendar(); $recur = $vcal->add('RRULE', ['FREQ' => 'DAILY', 'BYDAY' => 'mo,tu', 'BYMONTH' => [0, 1]]); - $this->assertEquals([ + self::assertEquals([ 'FREQ' => 'DAILY', 'BYDAY' => ['MO', 'TU'], 'BYMONTH' => [0, 1], ], $recur->getParts()); } - public function testGetJSONWithUntil() + public function testGetJSONWithUntil(): void { $input = 'BEGIN:VCALENDAR BEGIN:VEVENT @@ -92,10 +92,10 @@ public function testGetJSONWithUntil() $vcal = Reader::read($input); $rrule = $vcal->VEVENT->RRULE; $untilJsonString = $rrule->getJsonValue()[0]['until']; - $this->assertEquals('2016-03-05T23:00:00Z', $untilJsonString); + self::assertEquals('2016-03-05T23:00:00Z', $untilJsonString); } - public function testValidateStripEmpties() + public function testValidateStripEmpties(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -114,13 +114,13 @@ public function testValidateStripEmpties() '; $vcal = Reader::read($input); - $this->assertEquals( + self::assertCount( 1, - count($vcal->validate()) + $vcal->validate() ); - $this->assertEquals( + self::assertCount( 1, - count($vcal->validate($vcal::REPAIR)) + $vcal->validate($vcal::REPAIR) ); $expected = 'BEGIN:VCALENDAR @@ -139,13 +139,13 @@ public function testValidateStripEmpties() END:VCALENDAR '; - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $vcal ); } - public function testValidateStripNoFreq() + public function testValidateStripNoFreq(): void { $input = 'BEGIN:VCALENDAR VERSION:2.0 @@ -164,13 +164,13 @@ public function testValidateStripNoFreq() '; $vcal = Reader::read($input); - $this->assertEquals( + self::assertCount( 1, - count($vcal->validate()) + $vcal->validate() ); - $this->assertEquals( + self::assertCount( 1, - count($vcal->validate($vcal::REPAIR)) + $vcal->validate($vcal::REPAIR) ); $expected = 'BEGIN:VCALENDAR @@ -188,243 +188,243 @@ public function testValidateStripNoFreq() END:VCALENDAR '; - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $vcal ); } - public function testValidateInvalidByMonthRruleWithRepair() + public function testValidateInvalidByMonthRruleWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0'); $result = $property->validate(Node::REPAIR); - $this->assertCount(1, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue()); } - public function testValidateInvalidByMonthRruleWithoutRepair() + public function testValidateInvalidByMonthRruleWithoutRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0'); $result = $property->validate(); - $this->assertCount(1, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0', $property->getValue()); } - public function testValidateInvalidByMonthRruleWithRepair2() + public function testValidateInvalidByMonthRruleWithRepair2(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla'); $result = $property->validate(Node::REPAIR); - $this->assertCount(1, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue()); } - public function testValidateInvalidByMonthRruleWithoutRepair2() + public function testValidateInvalidByMonthRruleWithoutRepair2(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla'); $result = $property->validate(); - $this->assertCount(1, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); + self::assertCount(1, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); // Without repair the invalid BYMONTH is still there, but the value is changed to uppercase - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=BLA', $property->getValue()); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=BLA', $property->getValue()); } - public function testValidateInvalidByMonthRruleValue14WithRepair() + public function testValidateInvalidByMonthRruleValue14WithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=14'); $result = $property->validate(Node::REPAIR); - $this->assertCount(1, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24', $property->getValue()); } - public function testValidateInvalidByMonthRruleMultipleWithRepair() + public function testValidateInvalidByMonthRruleMultipleWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=0,1,2,3,4,14'); $result = $property->validate(Node::REPAIR); - $this->assertCount(2, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[1]['message']); - $this->assertEquals(1, $result[1]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=1,2,3,4', $property->getValue()); + self::assertCount(2, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[1]['message']); + self::assertEquals(1, $result[1]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=1,2,3,4', $property->getValue()); } - public function testValidateOneOfManyInvalidByMonthRruleWithRepair() + public function testValidateOneOfManyInvalidByMonthRruleWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=bla,3,foo'); $result = $property->validate(Node::REPAIR); - $this->assertCount(2, $result); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[1]['message']); - $this->assertEquals(1, $result[1]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=3', $property->getValue()); + self::assertCount(2, $result); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('BYMONTH in RRULE must have value(s) between 1 and 12!', $result[1]['message']); + self::assertEquals(1, $result[1]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=3', $property->getValue()); } - public function testValidateValidByMonthRrule() + public function testValidateValidByMonthRrule(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=2,3'); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=2,3', $property->getValue()); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYMONTHDAY=24;BYMONTH=2,3', $property->getValue()); } /** * test for issue #336. */ - public function testValidateRruleBySecondZero() + public function testValidateRruleBySecondZero(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=DAILY;BYHOUR=10;BYMINUTE=30;BYSECOND=0;UNTIL=20150616T153000Z'); $result = $property->validate(Node::REPAIR); // There should be 0 warnings and the value should be unchanged - $this->assertEmpty($result); - $this->assertEquals('FREQ=DAILY;BYHOUR=10;BYMINUTE=30;BYSECOND=0;UNTIL=20150616T153000Z', $property->getValue()); + self::assertEmpty($result); + self::assertEquals('FREQ=DAILY;BYHOUR=10;BYMINUTE=30;BYSECOND=0;UNTIL=20150616T153000Z', $property->getValue()); } - public function testValidateValidByWeekNoWithRepair() + public function testValidateValidByWeekNoWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=11'); $result = $property->validate(Node::REPAIR); - $this->assertCount(0, $result); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=11', $property->getValue()); + self::assertCount(0, $result); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=11', $property->getValue()); } - public function testValidateInvalidByWeekNoWithRepair() + public function testValidateInvalidByWeekNoWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE'); $result = $property->validate(Node::REPAIR); - $this->assertCount(1, $result); - $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); } - public function testValidateMultipleInvalidByWeekNoWithRepair() + public function testValidateMultipleInvalidByWeekNoWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55,2,-80;BYDAY=WE'); $result = $property->validate(Node::REPAIR); - $this->assertCount(2, $result); - $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[1]['message']); - $this->assertEquals(1, $result[1]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=2;BYDAY=WE', $property->getValue()); + self::assertCount(2, $result); + self::assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[1]['message']); + self::assertEquals(1, $result[1]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=2;BYDAY=WE', $property->getValue()); } - public function testValidateAllInvalidByWeekNoWithRepair() + public function testValidateAllInvalidByWeekNoWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55,-80;BYDAY=WE'); $result = $property->validate(Node::REPAIR); - $this->assertCount(2, $result); - $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[1]['message']); - $this->assertEquals(1, $result[1]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); + self::assertCount(2, $result); + self::assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[1]['message']); + self::assertEquals(1, $result[1]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); } - public function testValidateInvalidByWeekNoWithoutRepair() + public function testValidateInvalidByWeekNoWithoutRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE'); $result = $property->validate(); - $this->assertCount(1, $result); - $this->assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYWEEKNO in RRULE must have value(s) from -53 to -1, or 1 to 53!', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYWEEKNO=55;BYDAY=WE', $property->getValue()); } - public function testValidateValidByYearDayWithRepair() + public function testValidateValidByYearDayWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=119'); $result = $property->validate(Node::REPAIR); - $this->assertCount(0, $result); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=119', $property->getValue()); + self::assertCount(0, $result); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=119', $property->getValue()); } - public function testValidateInvalidByYearDayWithRepair() + public function testValidateInvalidByYearDayWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=367;BYDAY=WE'); $result = $property->validate(Node::REPAIR); - $this->assertCount(1, $result); - $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); } - public function testValidateMultipleInvalidByYearDayWithRepair() + public function testValidateMultipleInvalidByYearDayWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=380,2,-390;BYDAY=WE'); $result = $property->validate(Node::REPAIR); - $this->assertCount(2, $result); - $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[1]['message']); - $this->assertEquals(1, $result[1]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=2;BYDAY=WE', $property->getValue()); + self::assertCount(2, $result); + self::assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[1]['message']); + self::assertEquals(1, $result[1]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=2;BYDAY=WE', $property->getValue()); } - public function testValidateAllInvalidByYearDayWithRepair() + public function testValidateAllInvalidByYearDayWithRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=455,-480;BYDAY=WE'); $result = $property->validate(Node::REPAIR); - $this->assertCount(2, $result); - $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); - $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[1]['message']); - $this->assertEquals(1, $result[1]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); + self::assertCount(2, $result); + self::assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); + self::assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[1]['message']); + self::assertEquals(1, $result[1]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYDAY=WE', $property->getValue()); } - public function testValidateInvalidByYearDayWithoutRepair() + public function testValidateInvalidByYearDayWithoutRepair(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('RRULE', 'FREQ=YEARLY;COUNT=6;BYYEARDAY=380;BYDAY=WE'); $result = $property->validate(); - $this->assertCount(1, $result); - $this->assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); - $this->assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=380;BYDAY=WE', $property->getValue()); + self::assertCount(1, $result); + self::assertEquals('BYYEARDAY in RRULE must have value(s) from -366 to -1, or 1 to 366!', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); + self::assertEquals('FREQ=YEARLY;COUNT=6;BYYEARDAY=380;BYDAY=WE', $property->getValue()); } } diff --git a/tests/VObject/Property/TextTest.php b/tests/VObject/Property/TextTest.php index eea21b1ad..0fa320bfe 100644 --- a/tests/VObject/Property/TextTest.php +++ b/tests/VObject/Property/TextTest.php @@ -7,7 +7,7 @@ class TextTest extends TestCase { - public function assertVCard21Serialization($propValue, $expected) + public function assertVCard21Serialization($propValue, string $expected): void { $doc = new VCard([ 'VERSION' => '2.1', @@ -21,50 +21,50 @@ public function assertVCard21Serialization($propValue, $expected) $output = $doc->serialize(); - $this->assertEquals("BEGIN:VCARD\r\nVERSION:2.1\r\n$expected\r\nEND:VCARD\r\n", $output); + self::assertEquals("BEGIN:VCARD\r\nVERSION:2.1\r\n$expected\r\nEND:VCARD\r\n", $output); } - public function testSerializeVCard21() + public function testSerializeVCard21(): void { - $this->assertVCard21Serialization( + self::assertVCard21Serialization( 'f;oo', 'PROP;P1=V1:f;oo' ); } - public function testSerializeVCard21Array() + public function testSerializeVCard21Array(): void { - $this->assertVCard21Serialization( + self::assertVCard21Serialization( ['f;oo', 'bar'], 'PROP;P1=V1:f\;oo;bar' ); } - public function testSerializeVCard21Fold() + public function testSerializeVCard21Fold(): void { - $this->assertVCard21Serialization( + self::assertVCard21Serialization( str_repeat('x', 80), 'PROP;P1=V1:'.str_repeat('x', 64)."\r\n ".str_repeat('x', 16) ); } - public function testSerializeQuotedPrintable() + public function testSerializeQuotedPrintable(): void { - $this->assertVCard21Serialization( + self::assertVCard21Serialization( "foo\r\nbar", 'PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abar' ); } - public function testSerializeQuotedPrintableFold() + public function testSerializeQuotedPrintableFold(): void { - $this->assertVCard21Serialization( + self::assertVCard21Serialization( "foo\r\nbarxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "PROP;P1=V1;ENCODING=QUOTED-PRINTABLE:foo=0D=0Abarxxxxxxxxxxxxxxxxxxxxxxxxxx=\r\n xxx" ); } - public function testValidateMinimumPropValue() + public function testValidateMinimumPropValue(): void { $vcard = <<assertEquals(1, count($vcard->validate())); + self::assertCount(1, $vcard->validate()); - $this->assertEquals(1, count($vcard->N->getParts())); + self::assertCount(1, $vcard->N->getParts()); $vcard->validate(\Sabre\VObject\Node::REPAIR); - $this->assertEquals(5, count($vcard->N->getParts())); + self::assertCount(5, $vcard->N->getParts()); } } diff --git a/tests/VObject/Property/UriTest.php b/tests/VObject/Property/UriTest.php index d3d0e0f9c..edb7cc393 100644 --- a/tests/VObject/Property/UriTest.php +++ b/tests/VObject/Property/UriTest.php @@ -7,7 +7,7 @@ class UriTest extends TestCase { - public function testAlwaysEncodeUriVCalendar() + public function testAlwaysEncodeUriVCalendar(): void { // Apple iCal has issues with URL properties that don't have // VALUE=URI specified. We added a workaround to vobject that @@ -21,6 +21,6 @@ public function testAlwaysEncodeUriVCalendar() END:VCALENDAR ICS; $output = Reader::read($input)->serialize(); - $this->assertStringContainsString('URL;VALUE=URI:http://example.org/', $output); + self::assertStringContainsString('URL;VALUE=URI:http://example.org/', $output); } } diff --git a/tests/VObject/Property/VCard/DateAndOrTimeTest.php b/tests/VObject/Property/VCard/DateAndOrTimeTest.php index f21b408a1..8e2cb3207 100644 --- a/tests/VObject/Property/VCard/DateAndOrTimeTest.php +++ b/tests/VObject/Property/VCard/DateAndOrTimeTest.php @@ -11,15 +11,15 @@ class DateAndOrTimeTest extends TestCase /** * @dataProvider dates */ - public function testGetJsonValue($input, $output) + public function testGetJsonValue(string $input, string $output): void { $vcard = new VObject\Component\VCard(); $prop = $vcard->createProperty('BDAY', $input); - $this->assertEquals([$output], $prop->getJsonValue()); + self::assertEquals([$output], $prop->getJsonValue()); } - public function dates() + public function dates(): array { return [ [ @@ -81,7 +81,7 @@ public function dates() ]; } - public function testSetParts() + public function testSetParts(): void { $vcard = new VObject\Component\VCard(); @@ -90,10 +90,10 @@ public function testSetParts() new \DateTime('2014-04-02 18:37:00'), ]); - $this->assertEquals('20140402T183700Z', $prop->getValue()); + self::assertEquals('20140402T183700Z', $prop->getValue()); } - public function testSetPartsDateTimeImmutable() + public function testSetPartsDateTimeImmutable(): void { $vcard = new VObject\Component\VCard(); @@ -102,10 +102,10 @@ public function testSetPartsDateTimeImmutable() new \DateTimeImmutable('2014-04-02 18:37:00'), ]); - $this->assertEquals('20140402T183700Z', $prop->getValue()); + self::assertEquals('20140402T183700Z', $prop->getValue()); } - public function testSetPartsTooMany() + public function testSetPartsTooMany(): void { $this->expectException(\InvalidArgumentException::class); $vcard = new VObject\Component\VCard(); @@ -117,7 +117,7 @@ public function testSetPartsTooMany() ]); } - public function testSetPartsString() + public function testSetPartsString(): void { $vcard = new VObject\Component\VCard(); @@ -126,10 +126,10 @@ public function testSetPartsString() '20140402T183700Z', ]); - $this->assertEquals('20140402T183700Z', $prop->getValue()); + self::assertEquals('20140402T183700Z', $prop->getValue()); } - public function testSetValueDateTime() + public function testSetValueDateTime(): void { $vcard = new VObject\Component\VCard(); @@ -138,10 +138,10 @@ public function testSetValueDateTime() new \DateTime('2014-04-02 18:37:00') ); - $this->assertEquals('20140402T183700Z', $prop->getValue()); + self::assertEquals('20140402T183700Z', $prop->getValue()); } - public function testSetValueDateTimeImmutable() + public function testSetValueDateTimeImmutable(): void { $vcard = new VObject\Component\VCard(); @@ -150,10 +150,10 @@ public function testSetValueDateTimeImmutable() new \DateTimeImmutable('2014-04-02 18:37:00') ); - $this->assertEquals('20140402T183700Z', $prop->getValue()); + self::assertEquals('20140402T183700Z', $prop->getValue()); } - public function testSetDateTimeOffset() + public function testSetDateTimeOffset(): void { $vcard = new VObject\Component\VCard(); @@ -162,10 +162,10 @@ public function testSetDateTimeOffset() new \DateTime('2014-04-02 18:37:00', new \DateTimeZone('America/Toronto')) ); - $this->assertEquals('20140402T183700-0400', $prop->getValue()); + self::assertEquals('20140402T183700-0400', $prop->getValue()); } - public function testGetDateTime() + public function testGetDateTime(): void { $datetime = new \DateTime('2014-04-02 18:37:00', new \DateTimeZone('America/Toronto')); @@ -173,21 +173,21 @@ public function testGetDateTime() $prop = $vcard->createProperty('BDAY', $datetime); $dt = $prop->getDateTime(); - $this->assertEquals('2014-04-02T18:37:00-04:00', $dt->format('c'), 'For some reason this one failed. Current default timezone is: '.date_default_timezone_get()); + self::assertEquals('2014-04-02T18:37:00-04:00', $dt->format('c'), 'For some reason this one failed. Current default timezone is: '.date_default_timezone_get()); } - public function testGetDate() + public function testGetDate(): void { $datetime = new \DateTime('2014-04-02'); $vcard = new VObject\Component\VCard(); $prop = $vcard->createProperty('BDAY', $datetime, null, 'DATE'); - $this->assertEquals('DATE', $prop->getValueType()); - $this->assertEquals('BDAY:20140402', rtrim($prop->serialize())); + self::assertEquals('DATE', $prop->getValueType()); + self::assertEquals('BDAY:20140402', rtrim($prop->serialize())); } - public function testGetDateIncomplete() + public function testGetDateIncomplete(): void { $datetime = '--0407'; @@ -202,10 +202,10 @@ public function testGetDateIncomplete() $current = new \DateTime('now'); $year = $current->format('Y'); - $this->assertEquals($year.'0407', $dt->format('Ymd')); + self::assertEquals($year.'0407', $dt->format('Ymd')); } - public function testGetDateIncompleteFromVCard() + public function testGetDateIncompleteFromVCard(): void { $vcard = <<format('Y'); - $this->assertEquals($year.'0407', $dt->format('Ymd')); + self::assertEquals($year.'0407', $dt->format('Ymd')); } - public function testValidate() + public function testValidate(): void { $datetime = '--0407'; $vcard = new VObject\Component\VCard(); $prop = $vcard->add('BDAY', $datetime); - $this->assertEquals([], $prop->validate()); + self::assertEquals([], $prop->validate()); } - public function testValidateBroken() + public function testValidateBroken(): void { $datetime = '123'; $vcard = new VObject\Component\VCard(); $prop = $vcard->add('BDAY', $datetime); - $this->assertEquals([[ + self::assertEquals([[ 'level' => 3, 'message' => 'The supplied value (123) is not a correct DATE-AND-OR-TIME property', 'node' => $prop, diff --git a/tests/VObject/Property/VCard/LanguageTagTest.php b/tests/VObject/Property/VCard/LanguageTagTest.php index 54106ffe8..be3d5c62f 100644 --- a/tests/VObject/Property/VCard/LanguageTagTest.php +++ b/tests/VObject/Property/VCard/LanguageTagTest.php @@ -7,39 +7,39 @@ class LanguageTagTest extends TestCase { - public function testMimeDir() + public function testMimeDir(): void { $input = "BEGIN:VCARD\r\nVERSION:4.0\r\nLANG:nl\r\nEND:VCARD\r\n"; $mimeDir = new VObject\Parser\MimeDir($input); $result = $mimeDir->parse($input); - $this->assertInstanceOf(LanguageTag::class, $result->LANG); + self::assertInstanceOf(LanguageTag::class, $result->LANG); - $this->assertEquals('nl', $result->LANG->getValue()); + self::assertEquals('nl', $result->LANG->getValue()); - $this->assertEquals( + self::assertEquals( $input, $result->serialize() ); } - public function testChangeAndSerialize() + public function testChangeAndSerialize(): void { $input = "BEGIN:VCARD\r\nVERSION:4.0\r\nLANG:nl\r\nEND:VCARD\r\n"; $mimeDir = new VObject\Parser\MimeDir($input); $result = $mimeDir->parse($input); - $this->assertInstanceOf(LanguageTag::class, $result->LANG); + self::assertInstanceOf(LanguageTag::class, $result->LANG); // This replicates what the vcard converter does and triggered a bug in // the past. $result->LANG->setValue(['de']); - $this->assertEquals('de', $result->LANG->getValue()); + self::assertEquals('de', $result->LANG->getValue()); $expected = "BEGIN:VCARD\r\nVERSION:4.0\r\nLANG:de\r\nEND:VCARD\r\n"; - $this->assertEquals( + self::assertEquals( $expected, $result->serialize() ); diff --git a/tests/VObject/Property/VCard/PhoneNumberTest.php b/tests/VObject/Property/VCard/PhoneNumberTest.php index 668bc7e4c..f9882cdfb 100644 --- a/tests/VObject/Property/VCard/PhoneNumberTest.php +++ b/tests/VObject/Property/VCard/PhoneNumberTest.php @@ -7,13 +7,13 @@ class PhoneNumberTest extends TestCase { - public function testParser() + public function testParser(): void { $input = "BEGIN:VCARD\r\nVERSION:3.0\r\nTEL;TYPE=HOME;VALUE=PHONE-NUMBER:+1234\r\nEND:VCARD\r\n"; $vCard = VObject\Reader::read($input); - $this->assertInstanceOf(PhoneNumber::class, $vCard->TEL); - $this->assertEquals('PHONE-NUMBER', $vCard->TEL->getValueType()); - $this->assertEquals($input, $vCard->serialize()); + self::assertInstanceOf(PhoneNumber::class, $vCard->TEL); + self::assertEquals('PHONE-NUMBER', $vCard->TEL->getValueType()); + self::assertEquals($input, $vCard->serialize()); } } diff --git a/tests/VObject/PropertyTest.php b/tests/VObject/PropertyTest.php index 1f6e07022..b15e06b27 100644 --- a/tests/VObject/PropertyTest.php +++ b/tests/VObject/PropertyTest.php @@ -8,18 +8,18 @@ class PropertyTest extends TestCase { - public function testToString() + public function testToString(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); - $this->assertEquals('PROPNAME', $property->name); - $this->assertEquals('propvalue', $property->__toString()); - $this->assertEquals('propvalue', (string) $property); - $this->assertEquals('propvalue', $property->getValue()); + self::assertEquals('PROPNAME', $property->name); + self::assertEquals('propvalue', $property->__toString()); + self::assertEquals('propvalue', (string) $property); + self::assertEquals('propvalue', $property->getValue()); } - public function testCreate() + public function testCreate(): void { $cal = new VCalendar(); @@ -30,92 +30,92 @@ public function testCreate() $property = $cal->createProperty('propname', 'propvalue', $params); - $this->assertEquals('value1', $property['param1']->getValue()); - $this->assertEquals('value2', $property['param2']->getValue()); + self::assertEquals('value1', $property['param1']->getValue()); + self::assertEquals('value2', $property['param2']->getValue()); } - public function testSetValue() + public function testSetValue(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property->setValue('value2'); - $this->assertEquals('PROPNAME', $property->name); - $this->assertEquals('value2', $property->__toString()); + self::assertEquals('PROPNAME', $property->name); + self::assertEquals('value2', $property->__toString()); } - public function testParameterExists() + public function testParameterExists(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; - $this->assertTrue(isset($property['PARAMNAME'])); - $this->assertTrue(isset($property['paramname'])); - $this->assertFalse(isset($property['foo'])); + self::assertTrue(isset($property['PARAMNAME'])); + self::assertTrue(isset($property['paramname'])); + self::assertFalse(isset($property['foo'])); } - public function testParameterGet() + public function testParameterGet(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; - $this->assertInstanceOf(Parameter::class, $property['paramname']); + self::assertInstanceOf(Parameter::class, $property['paramname']); } - public function testParameterNotExists() + public function testParameterNotExists(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; - $this->assertNull($property['foo']); + self::assertNull($property['foo']); } - public function testParameterMultiple() + public function testParameterMultiple(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; $property->add('paramname', 'paramvalue'); - $this->assertInstanceOf(Parameter::class, $property['paramname']); - $this->assertEquals(2, count($property['paramname']->getParts())); + self::assertInstanceOf(Parameter::class, $property['paramname']); + self::assertCount(2, $property['paramname']->getParts()); } - public function testSetParameterAsString() + public function testSetParameterAsString(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; - $this->assertEquals(1, count($property->parameters())); - $this->assertInstanceOf(Parameter::class, $property->parameters['PARAMNAME']); - $this->assertEquals('PARAMNAME', $property->parameters['PARAMNAME']->name); - $this->assertEquals('paramvalue', $property->parameters['PARAMNAME']->getValue()); + self::assertCount(1, $property->parameters()); + self::assertInstanceOf(Parameter::class, $property->parameters['PARAMNAME']); + self::assertEquals('PARAMNAME', $property->parameters['PARAMNAME']->name); + self::assertEquals('paramvalue', $property->parameters['PARAMNAME']->getValue()); } - public function testUnsetParameter() + public function testUnsetParameter(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $property['paramname'] = 'paramvalue'; unset($property['PARAMNAME']); - $this->assertEquals(0, count($property->parameters())); + self::assertCount(0, $property->parameters()); } - public function testSerialize() + public function testSerialize(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); - $this->assertEquals("PROPNAME:propvalue\r\n", $property->serialize()); + self::assertEquals("PROPNAME:propvalue\r\n", $property->serialize()); } - public function testSerializeParam() + public function testSerializeParam(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue', [ @@ -123,18 +123,18 @@ public function testSerializeParam() 'paramname2' => 'paramvalue2', ]); - $this->assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n", $property->serialize()); + self::assertEquals("PROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propvalue\r\n", $property->serialize()); } - public function testSerializeNewLine() + public function testSerializeNewLine(): void { $cal = new VCalendar(); $property = $cal->createProperty('SUMMARY', "line1\nline2"); - $this->assertEquals("SUMMARY:line1\\nline2\r\n", $property->serialize()); + self::assertEquals("SUMMARY:line1\\nline2\r\n", $property->serialize()); } - public function testSerializeLongLine() + public function testSerializeLongLine(): void { $cal = new VCalendar(); $value = str_repeat('!', 200); @@ -142,10 +142,10 @@ public function testSerializeLongLine() $expected = 'PROPNAME:'.str_repeat('!', 66)."\r\n ".str_repeat('!', 74)."\r\n ".str_repeat('!', 60)."\r\n"; - $this->assertEquals($expected, $property->serialize()); + self::assertEquals($expected, $property->serialize()); } - public function testSerializeUTF8LineFold() + public function testSerializeUTF8LineFold(): void { $cal = new VCalendar(); $value = str_repeat('!', 65)."\xc3\xa4bla".str_repeat('!', 142)."\xc3\xa4foo"; // inserted umlaut-a @@ -156,53 +156,53 @@ public function testSerializeUTF8LineFold() // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! (" " + 73x"!" = 74 bytes) // äfoo $expected = 'PROPNAME:'.str_repeat('!', 65)."\r\n \xc3\xa4bla".str_repeat('!', 69)."\r\n ".str_repeat('!', 73)."\r\n \xc3\xa4foo\r\n"; - $this->assertEquals($expected, $property->serialize()); + self::assertEquals($expected, $property->serialize()); } - public function testGetIterator() + public function testGetIterator(): void { $cal = new VCalendar(); $it = new ElementList([]); $property = $cal->createProperty('propname', 'propvalue'); $property->setIterator($it); - $this->assertEquals($it, $property->getIterator()); + self::assertEquals($it, $property->getIterator()); } - public function testGetIteratorDefault() + public function testGetIteratorDefault(): void { $cal = new VCalendar(); $property = $cal->createProperty('propname', 'propvalue'); $it = $property->getIterator(); - $this->assertTrue($it instanceof ElementList); - $this->assertEquals(1, count($it)); + self::assertTrue($it instanceof ElementList); + self::assertCount(1, $it); } - public function testAddScalar() + public function testAddScalar(): void { $cal = new VCalendar(); $property = $cal->createProperty('EMAIL'); $property->add('myparam', 'value'); - $this->assertEquals(1, count($property->parameters())); + self::assertCount(1, $property->parameters()); - $this->assertTrue($property->parameters['MYPARAM'] instanceof Parameter); - $this->assertEquals('MYPARAM', $property->parameters['MYPARAM']->name); - $this->assertEquals('value', $property->parameters['MYPARAM']->getValue()); + self::assertTrue($property->parameters['MYPARAM'] instanceof Parameter); + self::assertEquals('MYPARAM', $property->parameters['MYPARAM']->name); + self::assertEquals('value', $property->parameters['MYPARAM']->getValue()); } - public function testAddParameter() + public function testAddParameter(): void { $cal = new VCalendar(); $prop = $cal->createProperty('EMAIL'); $prop->add('MYPARAM', 'value'); - $this->assertEquals(1, count($prop->parameters())); - $this->assertEquals('MYPARAM', $prop['myparam']->name); + self::assertCount(1, $prop->parameters()); + self::assertEquals('MYPARAM', $prop['myparam']->name); } - public function testAddParameterTwice() + public function testAddParameterTwice(): void { $cal = new VCalendar(); $prop = $cal->createProperty('EMAIL'); @@ -210,13 +210,13 @@ public function testAddParameterTwice() $prop->add('MYPARAM', 'value1'); $prop->add('MYPARAM', 'value2'); - $this->assertEquals(1, count($prop->parameters)); - $this->assertEquals(2, count($prop->parameters['MYPARAM']->getParts())); + self::assertCount(1, $prop->parameters); + self::assertCount(2, $prop->parameters['MYPARAM']->getParts()); - $this->assertEquals('MYPARAM', $prop['MYPARAM']->name); + self::assertEquals('MYPARAM', $prop['MYPARAM']->name); } - public function testClone() + public function testClone(): void { $cal = new VCalendar(); $property = $cal->createProperty('EMAIL', 'value'); @@ -225,10 +225,10 @@ public function testClone() $property2 = clone $property; $property['FOO'] = 'BAZ'; - $this->assertEquals('BAR', (string) $property2['FOO']); + self::assertEquals('BAR', (string) $property2['FOO']); } - public function testCreateParams() + public function testCreateParams(): void { $cal = new VCalendar(); $property = $cal->createProperty('X-PROP', 'value', [ @@ -236,21 +236,21 @@ public function testCreateParams() 'param2' => ['value2', 'value3'], ]); - $this->assertEquals(1, count($property['PARAM1']->getParts())); - $this->assertEquals(2, count($property['PARAM2']->getParts())); + self::assertCount(1, $property['PARAM1']->getParts()); + self::assertCount(2, $property['PARAM2']->getParts()); } - public function testValidateNonUTF8() + public function testValidateNonUTF8(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('X-PROP', "Bla\x00"); $result = $property->validate(Property::REPAIR); - $this->assertEquals('Property contained a control character (0x00)', $result[0]['message']); - $this->assertEquals('Bla', $property->getValue()); + self::assertEquals('Property contained a control character (0x00)', $result[0]['message']); + self::assertEquals('Bla', $property->getValue()); } - public function testValidateControlChars() + public function testValidateControlChars(): void { $s = 'chars['; foreach ([ @@ -268,48 +268,54 @@ public function testValidateControlChars() $property = $calendar->createProperty('X-PROP', $s); $result = $property->validate(Property::REPAIR); - $this->assertEquals('Property contained a control character (0x7f)', $result[0]['message']); - $this->assertEquals("chars[7F()5E(^)5C(\\\\)3B(\\;)3A(:)2C(\\,)22(\")20( )1F()1E()1D()1C()1B()1A()19()18()17()16()15()14()13()12()11()10()0F()0E()0D()0C()0B()0A(\\n)09(\t)08()07()06()05()04()03()02()01()00()]end", $property->getRawMimeDirValue()); + self::assertEquals('Property contained a control character (0x7f)', $result[0]['message']); + self::assertEquals("chars[7F()5E(^)5C(\\\\)3B(\\;)3A(:)2C(\\,)22(\")20( )1F()1E()1D()1C()1B()1A()19()18()17()16()15()14()13()12()11()10()0F()0E()0D()0C()0B()0A(\\n)09(\t)08()07()06()05()04()03()02()01()00()]end", $property->getRawMimeDirValue()); } - public function testValidateBadPropertyName() + /** + * @throws InvalidDataException + */ + public function testValidateBadPropertyName(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('X_*&PROP*', 'Bla'); - $result = $property->validate(Property::REPAIR); + $result = $property->validate(Node::REPAIR); - $this->assertEquals($result[0]['message'], 'The propertyname: X_*&PROP* contains invalid characters. Only A-Z, 0-9 and - are allowed'); - $this->assertEquals('X-PROP', $property->name); + self::assertEquals('The property name: X_*&PROP* contains invalid characters. Only A-Z, 0-9 and - are allowed', $result[0]['message']); + self::assertEquals('X-PROP', $property->name); } - public function testGetValue() + /** + * @throws InvalidDataException + */ + public function testGetValue(): void { $calendar = new VCalendar(); $property = $calendar->createProperty('SUMMARY', null); - $this->assertEquals([], $property->getParts()); - $this->assertNull($property->getValue()); + self::assertEquals([], $property->getParts()); + self::assertNull($property->getValue()); $property->setValue([]); - $this->assertEquals([], $property->getParts()); - $this->assertNull($property->getValue()); + self::assertEquals([], $property->getParts()); + self::assertNull($property->getValue()); $property->setValue([1]); - $this->assertEquals([1], $property->getParts()); - $this->assertEquals(1, $property->getValue()); + self::assertEquals([1], $property->getParts()); + self::assertEquals(1, $property->getValue()); $property->setValue([1, 2]); - $this->assertEquals([1, 2], $property->getParts()); - $this->assertEquals('1,2', $property->getValue()); + self::assertEquals([1, 2], $property->getParts()); + self::assertEquals('1,2', $property->getValue()); $property->setValue('str'); - $this->assertEquals(['str'], $property->getParts()); - $this->assertEquals('str', $property->getValue()); + self::assertEquals(['str'], $property->getParts()); + self::assertEquals('str', $property->getValue()); } /** * ElementList should reject this. */ - public function testArrayAccessSetInt() + public function testArrayAccessSetInt(): void { $this->expectException(\LogicException::class); $calendar = new VCalendar(); @@ -322,7 +328,7 @@ public function testArrayAccessSetInt() /** * ElementList should reject this. */ - public function testArrayAccessUnsetInt() + public function testArrayAccessUnsetInt(): void { $this->expectException(\LogicException::class); $calendar = new VCalendar(); @@ -332,7 +338,7 @@ public function testArrayAccessUnsetInt() unset($calendar->{'X-PROP'}[0]); } - public function testValidateBadEncoding() + public function testValidateBadEncoding(): void { $document = new VCalendar(); $property = $document->add('X-FOO', 'value'); @@ -340,11 +346,11 @@ public function testValidateBadEncoding() $result = $property->validate(); - $this->assertEquals('ENCODING=INVALID is not valid for this document type.', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); + self::assertEquals('ENCODING=INVALID is not valid for this document type.', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); } - public function testValidateBadEncodingVCard4() + public function testValidateBadEncodingVCard4(): void { $document = new VCard(['VERSION' => '4.0']); $property = $document->add('X-FOO', 'value'); @@ -352,11 +358,11 @@ public function testValidateBadEncodingVCard4() $result = $property->validate(); - $this->assertEquals('ENCODING parameter is not valid in vCard 4.', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); + self::assertEquals('ENCODING parameter is not valid in vCard 4.', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); } - public function testValidateBadEncodingVCard3() + public function testValidateBadEncodingVCard3(): void { $document = new VCard(['VERSION' => '3.0']); $property = $document->add('X-FOO', 'value'); @@ -364,17 +370,17 @@ public function testValidateBadEncodingVCard3() $result = $property->validate(); - $this->assertEquals('ENCODING=BASE64 is not valid for this document type.', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); + self::assertEquals('ENCODING=BASE64 is not valid for this document type.', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); - //Validate the reparation of BASE64 formatted vCard v3 + // Validate the reparation of BASE64 formatted vCard v3 $result = $property->validate(Property::REPAIR); - $this->assertEquals('ENCODING=BASE64 has been transformed to ENCODING=B.', $result[0]['message']); - $this->assertEquals(1, $result[0]['level']); + self::assertEquals('ENCODING=BASE64 has been transformed to ENCODING=B.', $result[0]['message']); + self::assertEquals(1, $result[0]['level']); } - public function testValidateBadEncodingVCard21() + public function testValidateBadEncodingVCard21(): void { $document = new VCard(['VERSION' => '2.1']); $property = $document->add('X-FOO', 'value'); @@ -382,7 +388,7 @@ public function testValidateBadEncodingVCard21() $result = $property->validate(); - $this->assertEquals('ENCODING=B is not valid for this document type.', $result[0]['message']); - $this->assertEquals(3, $result[0]['level']); + self::assertEquals('ENCODING=B is not valid for this document type.', $result[0]['message']); + self::assertEquals(3, $result[0]['level']); } } diff --git a/tests/VObject/ReaderTest.php b/tests/VObject/ReaderTest.php index 96ed56be0..336a291ab 100644 --- a/tests/VObject/ReaderTest.php +++ b/tests/VObject/ReaderTest.php @@ -6,18 +6,18 @@ class ReaderTest extends TestCase { - public function testReadComponent() + public function testReadComponent(): void { $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR"; $result = Reader::read($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadStream() + public function testReadStream(): void { $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR"; @@ -27,101 +27,106 @@ public function testReadStream() $result = Reader::read($stream); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadComponentUnixNewLine() + public function testReadComponentUnixNewLine(): void { $data = "BEGIN:VCALENDAR\nEND:VCALENDAR"; $result = Reader::read($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadComponentLineFold() + public function testReadComponentLineFold(): void { $data = "BEGIN:\r\n\tVCALENDAR\r\nE\r\n ND:VCALENDAR"; $result = Reader::read($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadCorruptComponent() + public function testReadCorruptComponent(): void { $this->expectException(ParseException::class); $data = "BEGIN:VCALENDAR\r\nEND:FOO"; - $result = Reader::read($data); + Reader::read($data); } - public function testReadCorruptSubComponent() + public function testReadCorruptSubComponent(): void { $this->expectException(ParseException::class); $data = "BEGIN:VCALENDAR\r\nBEGIN:VEVENT\r\nEND:FOO\r\nEND:VCALENDAR"; - $result = Reader::read($data); + Reader::read($data); } - public function testReadProperty() + public function testReadProperty(): void { $data = "BEGIN:VCALENDAR\r\nSUMMARY:propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->SUMMARY; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('SUMMARY', $result->name); - $this->assertEquals('propValue', $result->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('SUMMARY', $result->name); + self::assertEquals('propValue', $result->getValue()); } - public function testReadPropertyWithNewLine() + public function testReadPropertyWithNewLine(): void { $data = "BEGIN:VCALENDAR\r\nSUMMARY:Line1\\nLine2\\NLine3\\\\Not the 4th line!\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->SUMMARY; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('SUMMARY', $result->name); - $this->assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('SUMMARY', $result->name); + self::assertEquals("Line1\nLine2\nLine3\\Not the 4th line!", $result->getValue()); } - public function testReadMappedProperty() + public function testReadMappedProperty(): void { $data = "BEGIN:VCALENDAR\r\nDTSTART:20110529\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->DTSTART; - $this->assertInstanceOf(Property\ICalendar\DateTime::class, $result); - $this->assertEquals('DTSTART', $result->name); - $this->assertEquals('20110529', $result->getValue()); + self::assertInstanceOf(Property\ICalendar\DateTime::class, $result); + self::assertEquals('DTSTART', $result->name); + self::assertEquals('20110529', $result->getValue()); } - public function testReadMappedPropertyGrouped() + public function testReadMappedPropertyGrouped(): void { $data = "BEGIN:VCALENDAR\r\nfoo.DTSTART:20110529\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->DTSTART; - $this->assertInstanceOf(Property\ICalendar\DateTime::class, $result); - $this->assertEquals('DTSTART', $result->name); - $this->assertEquals('20110529', $result->getValue()); + self::assertInstanceOf(Property\ICalendar\DateTime::class, $result); + self::assertEquals('DTSTART', $result->name); + self::assertEquals('20110529', $result->getValue()); } - public function testReadBrokenLine() + public function testReadMissingEnd(): void { - $this->expectException(ParseException::class); - $data = "BEGIN:VCALENDAR\r\nPROPNAME;propValue"; + $data = "BEGIN:VCALENDAR\r\nPROPNAME:propValue"; $result = Reader::read($data); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(1, $result->children()); + self::assertInstanceOf(Property::class, $result->children()[0]); + self::assertEquals('PROPNAME', $result->children()[0]->name); + self::assertEquals('propValue', $result->children()[0]->getValue()); } - public function testReadPropertyInComponent() + public function testReadPropertyInComponent(): void { $data = [ 'BEGIN:VCALENDAR', @@ -131,15 +136,15 @@ public function testReadPropertyInComponent() $result = Reader::read(implode("\r\n", $data)); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(1, count($result->children())); - $this->assertInstanceOf(Property::class, $result->children()[0]); - $this->assertEquals('PROPNAME', $result->children()[0]->name); - $this->assertEquals('propValue', $result->children()[0]->getValue()); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(1, $result->children()); + self::assertInstanceOf(Property::class, $result->children()[0]); + self::assertEquals('PROPNAME', $result->children()[0]->name); + self::assertEquals('propValue', $result->children()[0]->getValue()); } - public function testReadNestedComponent() + public function testReadNestedComponent(): void { $data = [ 'BEGIN:VCALENDAR', @@ -152,157 +157,157 @@ public function testReadNestedComponent() $result = Reader::read(implode("\r\n", $data)); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(1, count($result->children())); - $this->assertInstanceOf(Component::class, $result->children()[0]); - $this->assertEquals('VTIMEZONE', $result->children()[0]->name); - $this->assertEquals(1, count($result->children()[0]->children())); - $this->assertInstanceOf(Component::class, $result->children()[0]->children()[0]); - $this->assertEquals('DAYLIGHT', $result->children()[0]->children()[0]->name); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(1, $result->children()); + self::assertInstanceOf(Component::class, $result->children()[0]); + self::assertEquals('VTIMEZONE', $result->children()[0]->name); + self::assertCount(1, $result->children()[0]->children()); + self::assertInstanceOf(Component::class, $result->children()[0]->children()[0]); + self::assertEquals('DAYLIGHT', $result->children()[0]->children()[0]->name); } - public function testReadPropertyParameter() + public function testReadPropertyParameter(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue:propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); - $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); + self::assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); } - public function testReadPropertyRepeatingParameter() + public function testReadPropertyRepeatingParameter(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;N=1;N=2;N=3,4;N=\"5\",6;N=\"7,8\";N=9,10;N=^'11^':propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('N', $result->parameters['N']->name); - $this->assertEquals('1,2,3,4,5,6,7,8,9,10,"11"', $result->parameters['N']->getValue()); - $this->assertEquals([1, 2, 3, 4, 5, 6, '7,8', 9, 10, '"11"'], $result->parameters['N']->getParts()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('N', $result->parameters['N']->name); + self::assertEquals('1,2,3,4,5,6,7,8,9,10,"11"', $result->parameters['N']->getValue()); + self::assertEquals([1, 2, 3, 4, 5, 6, '7,8', 9, 10, '"11"'], $result->parameters['N']->getParts()); } - public function testReadPropertyRepeatingNamelessGuessedParameter() + public function testReadPropertyRepeatingNamelessGuessedParameter(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;WORK;VOICE;PREF:propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('TYPE', $result->parameters['TYPE']->name); - $this->assertEquals('WORK,VOICE,PREF', $result->parameters['TYPE']->getValue()); - $this->assertEquals(['WORK', 'VOICE', 'PREF'], $result->parameters['TYPE']->getParts()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('TYPE', $result->parameters['TYPE']->name); + self::assertEquals('WORK,VOICE,PREF', $result->parameters['TYPE']->getValue()); + self::assertEquals(['WORK', 'VOICE', 'PREF'], $result->parameters['TYPE']->getParts()); } - public function testReadPropertyNoName() + public function testReadPropertyNoName(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PRODIGY:propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('TYPE', $result->parameters['TYPE']->name); - $this->assertTrue($result->parameters['TYPE']->noName); - $this->assertEquals('PRODIGY', $result->parameters['TYPE']); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('TYPE', $result->parameters['TYPE']->name); + self::assertTrue($result->parameters['TYPE']->noName); + self::assertEquals('PRODIGY', $result->parameters['TYPE']); } - public function testReadPropertyParameterExtraColon() + public function testReadPropertyParameterExtraColon(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue:propValue:anotherrandomstring\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue:anotherrandomstring', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); - $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue:anotherrandomstring', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); + self::assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); } - public function testReadProperty2Parameters() + public function testReadProperty2Parameters(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue;PARAMNAME2=paramvalue2:propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(2, count($result->parameters())); - $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); - $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); - $this->assertEquals('PARAMNAME2', $result->parameters['PARAMNAME2']->name); - $this->assertEquals('paramvalue2', $result->parameters['PARAMNAME2']->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(2, $result->parameters()); + self::assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); + self::assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); + self::assertEquals('PARAMNAME2', $result->parameters['PARAMNAME2']->name); + self::assertEquals('paramvalue2', $result->parameters['PARAMNAME2']->getValue()); } - public function testReadPropertyParameterQuoted() + public function testReadPropertyParameterQuoted(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=\"paramvalue\":propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); - $this->assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); + self::assertEquals('paramvalue', $result->parameters['PARAMNAME']->getValue()); } - public function testReadPropertyParameterNewLines() + public function testReadPropertyParameterNewLines(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue1^nvalue2^^nvalue3:propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); - $this->assertEquals("paramvalue1\nvalue2^nvalue3", $result->parameters['PARAMNAME']->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); + self::assertEquals("paramvalue1\nvalue2^nvalue3", $result->parameters['PARAMNAME']->getValue()); } - public function testReadPropertyParameterQuotedColon() + public function testReadPropertyParameterQuotedColon(): void { $data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=\"param:value\":propValue\r\nEND:VCALENDAR"; $result = Reader::read($data); $result = $result->PROPNAME; - $this->assertInstanceOf(Property::class, $result); - $this->assertEquals('PROPNAME', $result->name); - $this->assertEquals('propValue', $result->getValue()); - $this->assertEquals(1, count($result->parameters())); - $this->assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); - $this->assertEquals('param:value', $result->parameters['PARAMNAME']->getValue()); + self::assertInstanceOf(Property::class, $result); + self::assertEquals('PROPNAME', $result->name); + self::assertEquals('propValue', $result->getValue()); + self::assertCount(1, $result->parameters()); + self::assertEquals('PARAMNAME', $result->parameters['PARAMNAME']->name); + self::assertEquals('param:value', $result->parameters['PARAMNAME']->getValue()); } - public function testReadForgiving() + public function testReadForgiving(): void { $data = [ 'BEGIN:VCALENDAR', @@ -312,12 +317,12 @@ public function testReadForgiving() $caught = false; try { - $result = Reader::read(implode("\r\n", $data)); + Reader::read(implode("\r\n", $data)); } catch (ParseException $e) { $caught = true; } - $this->assertEquals(true, $caught); + self::assertEquals(true, $caught); $result = Reader::read(implode("\r\n", $data), Reader::OPTION_FORGIVING); @@ -328,10 +333,10 @@ public function testReadForgiving() '', ]); - $this->assertEquals($expected, $result->serialize()); + self::assertEquals($expected, $result->serialize()); } - public function testReadWithInvalidLine() + public function testReadWithInvalidLine(): void { $data = [ 'BEGIN:VCALENDAR', @@ -342,12 +347,12 @@ public function testReadWithInvalidLine() $caught = false; try { - $result = Reader::read(implode("\r\n", $data)); + Reader::read(implode("\r\n", $data)); } catch (ParseException $e) { $caught = true; } - $this->assertEquals(true, $caught); + self::assertEquals(true, $caught); $result = Reader::read(implode("\r\n", $data), Reader::OPTION_IGNORE_INVALID_LINES); @@ -358,13 +363,13 @@ public function testReadWithInvalidLine() '', ]); - $this->assertEquals($expected, $result->serialize()); + self::assertEquals($expected, $result->serialize()); } /** * Reported as Issue 32. */ - public function testReadIncompleteFile() + public function testReadIncompleteFile(): void { $this->expectException(ParseException::class); $input = <<expectException(\InvalidArgumentException::class); Reader::read(false); } - public function testReadBOM() + public function testReadBOM(): void { - $data = chr(0xef).chr(0xbb).chr(0xbf)."BEGIN:VCALENDAR\r\nEND:VCALENDAR"; + $data = chr(0xEF).chr(0xBB).chr(0xBF)."BEGIN:VCALENDAR\r\nEND:VCALENDAR"; $result = Reader::read($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadXMLComponent() + public function testReadXMLComponent(): void { $data = << @@ -425,12 +430,12 @@ public function testReadXMLComponent() $result = Reader::readXML($data); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadXMLStream() + public function testReadXMLStream(): void { $data = << @@ -446,12 +451,12 @@ public function testReadXMLStream() $result = Reader::readXML($stream); - $this->assertInstanceOf(Component::class, $result); - $this->assertEquals('VCALENDAR', $result->name); - $this->assertEquals(0, count($result->children())); + self::assertInstanceOf(Component::class, $result); + self::assertEquals('VCALENDAR', $result->name); + self::assertCount(0, $result->children()); } - public function testReadDuplicateValue() + public function testReadDuplicateValue(): void { $input = <<assertSame($expected, $result->VEVENT->DTSTART->serialize()); + self::assertSame($expected, $result->VEVENT->DTSTART->serialize()); } } diff --git a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php index bd1eeb9b6..9b6b20df4 100644 --- a/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php +++ b/tests/VObject/Recur/EventIterator/ByMonthInDailyTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -12,7 +11,7 @@ class ByMonthInDailyTest extends TestCase /** * This tests the expansion of dates with DAILY frequency in RRULE with BYMONTH restrictions. */ - public function testExpand() + public function testExpand(): void { $ics = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $vcal = $vcal->expand(new DateTime('2013-09-28'), new DateTime('2014-09-11')); + $vcal = $vcal->expand(new \DateTime('2013-09-28'), new \DateTime('2014-09-11')); $dates = []; foreach ($vcal->VEVENT as $event) { @@ -55,6 +54,6 @@ public function testExpand() '20140907T160000Z', ]; - $this->assertEquals($expectedDates, $dates, 'Recursed dates are restricted by month'); + self::assertEquals($expectedDates, $dates, 'Recursed dates are restricted by month'); } } diff --git a/tests/VObject/Recur/EventIterator/BySetPosHangTest.php b/tests/VObject/Recur/EventIterator/BySetPosHangTest.php index 555f2ffd4..f5132e1d2 100644 --- a/tests/VObject/Recur/EventIterator/BySetPosHangTest.php +++ b/tests/VObject/Recur/EventIterator/BySetPosHangTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -15,7 +14,7 @@ class BySetPosHangTest extends TestCase * * See: https://github.com/fruux/sabre-vobject/issues/212 */ - public function testExpand() + public function testExpand(): void { $ics = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2016-01-01')); + $vcal = $vcal->expand(new \DateTime('2015-01-01'), new \DateTime('2016-01-01')); $dates = []; foreach ($vcal->VEVENT as $event) { @@ -57,6 +56,6 @@ public function testExpand() '20151224T160000Z', ]; - $this->assertEquals($expectedDates, $dates); + self::assertEquals($expectedDates, $dates); } } diff --git a/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php b/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php index 605e10dde..a7a39d1dd 100644 --- a/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php +++ b/tests/VObject/Recur/EventIterator/ExpandFloatingTimesTest.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -12,7 +10,7 @@ class ExpandFloatingTimesTest extends TestCase { use \Sabre\VObject\PHPUnitAssertions; - public function testExpand() + public function testExpand(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-01-31')); + $vcal = $vcal->expand(new \DateTime('2015-01-01'), new \DateTime('2015-01-31')); $output = <<assertVObjectEqualsVObject($output, $vcal); + self::assertVObjectEqualsVObject($output, $vcal); } - public function testExpandWithReferenceTimezone() + public function testExpandWithReferenceTimezone(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); $vcal = $vcal->expand( - new DateTime('2015-01-01'), - new DateTime('2015-01-31'), - new DateTimeZone('Europe/Berlin') + new \DateTime('2015-01-01'), + new \DateTime('2015-01-31'), + new \DateTimeZone('Europe/Berlin') ); $output = <<assertVObjectEqualsVObject($output, $vcal); + self::assertVObjectEqualsVObject($output, $vcal); } } diff --git a/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php b/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php index 3db97ede2..8391a232a 100644 --- a/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php +++ b/tests/VObject/Recur/EventIterator/FifthTuesdayProblemTest.php @@ -14,7 +14,7 @@ class FifthTuesdayProblemTest extends TestCase * * @medium */ - public function testGetDTEnd() + public function testGetDTEnd(): void { $ics = <<assertTrue(true); + self::assertTrue(true); } } diff --git a/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php b/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php index 548820191..4f434dd2a 100644 --- a/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php +++ b/tests/VObject/Recur/EventIterator/HandleRDateExpandTest.php @@ -2,19 +2,16 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; /** - * This is a unittest for Issue #53. + * This is a unit test for Issue #53. */ class HandleRDateExpandTest extends TestCase { - public function testExpand() + public function testExpand(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $vcal = $vcal->expand(new DateTime('2015-01-01'), new DateTime('2015-12-01')); + $vcal = $vcal->expand(new \DateTime('2015-01-01'), new \DateTime('2015-12-01')); $result = iterator_to_array($vcal->VEVENT); - $this->assertEquals(5, count($result)); + self::assertCount(5, $result); - $utc = new DateTimeZone('UTC'); + $utc = new \DateTimeZone('UTC'); $expected = [ - new DateTimeImmutable('2015-10-12', $utc), - new DateTimeImmutable('2015-10-15', $utc), - new DateTimeImmutable('2015-10-17', $utc), - new DateTimeImmutable('2015-10-18', $utc), - new DateTimeImmutable('2015-10-20', $utc), + new \DateTimeImmutable('2015-10-12', $utc), + new \DateTimeImmutable('2015-10-15', $utc), + new \DateTimeImmutable('2015-10-17', $utc), + new \DateTimeImmutable('2015-10-18', $utc), + new \DateTimeImmutable('2015-10-20', $utc), ]; $result = array_map(function ($ev) {return $ev->DTSTART->getDateTime(); }, $result); - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } } diff --git a/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php b/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php index f9fcda442..b0ecbbdbf 100644 --- a/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php +++ b/tests/VObject/Recur/EventIterator/IncorrectExpandTest.php @@ -2,19 +2,18 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; /** - * This is a unittest for Issue #53. + * This is a unit test for Issue #53. */ class IncorrectExpandTest extends TestCase { use \Sabre\VObject\PHPUnitAssertions; - public function testExpand() + public function testExpand(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $vcal = $vcal->expand(new DateTime('2011-01-01'), new DateTime('2014-01-01')); + $vcal = $vcal->expand(new \DateTime('2011-01-01'), new \DateTime('2014-01-01')); $output = <<assertVObjectEqualsVObject($output, $vcal); + self::assertVObjectEqualsVObject($output, $vcal); } } diff --git a/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php b/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php index 5546c508d..591140e6d 100644 --- a/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php +++ b/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\InvalidDataException; @@ -11,8 +9,7 @@ class InfiniteLoopProblemTest extends TestCase { - /** @var VCalendar */ - private $vcal; + private VCalendar $vcal; public function setUp(): void { @@ -23,20 +20,20 @@ public function setUp(): void * This bug came from a Fruux customer. This would result in a never-ending * request. */ - public function testFastForwardTooFar() + public function testFastForwardTooFar(): void { $ev = $this->vcal->createComponent('VEVENT'); $ev->UID = 'foobar'; $ev->DTSTART = '20090420T180000Z'; $ev->RRULE = 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1'; - $this->assertFalse($ev->isInTimeRange(new DateTimeImmutable('2012-01-01 12:00:00'), new DateTimeImmutable('3000-01-01 00:00:00'))); + self::assertFalse($ev->isInTimeRange(new \DateTimeImmutable('2012-01-01 12:00:00'), new \DateTimeImmutable('3000-01-01 00:00:00'))); } /** * Different bug, also likely an infinite loop. */ - public function testYearlyByMonthLoop() + public function testYearlyByMonthLoop(): void { $ev = $this->vcal->createComponent('VEVENT'); $ev->UID = 'uuid'; @@ -55,20 +52,20 @@ public function testYearlyByMonthLoop() $this->vcal->add($ev); $it = new Recur\EventIterator($this->vcal, 'uuid'); - $it->fastForward(new DateTimeImmutable('2012-01-29 23:00:00', new DateTimeZone('UTC'))); + $it->fastForward(new \DateTimeImmutable('2012-01-29 23:00:00', new \DateTimeZone('UTC'))); $collect = []; while ($it->valid()) { $collect[] = $it->getDtStart(); - if ($it->getDtStart() > new DateTimeImmutable('2013-02-05 22:59:59', new DateTimeZone('UTC'))) { + if ($it->getDtStart() > new \DateTimeImmutable('2013-02-05 22:59:59', new \DateTimeZone('UTC'))) { break; } $it->next(); } - $this->assertEquals( - [new DateTimeImmutable('2012-02-01 15:45:00', new DateTimeZone('Europe/Berlin'))], + self::assertEquals( + [new \DateTimeImmutable('2012-02-01 15:45:00', new \DateTimeZone('Europe/Berlin'))], $collect ); } @@ -78,7 +75,7 @@ public function testYearlyByMonthLoop() * this means we increase the current day (or week, month) by 0, this also * results in an infinite loop. */ - public function testZeroInterval() + public function testZeroInterval(): void { $this->expectException(InvalidDataException::class); $ev = $this->vcal->createComponent('VEVENT'); @@ -88,8 +85,8 @@ public function testZeroInterval() $this->vcal->add($ev); $it = new Recur\EventIterator($this->vcal, 'uuid'); - $it->fastForward(new DateTimeImmutable('2013-01-01 23:00:00', new DateTimeZone('UTC'))); + $it->fastForward(new \DateTimeImmutable('2013-01-01 23:00:00', new \DateTimeZone('UTC'))); - // if we got this far.. it means we are no longer infinitely looping + // if we got this far it means we are no longer infinitely looping } } diff --git a/tests/VObject/Recur/EventIterator/Issue26Test.php b/tests/VObject/Recur/EventIterator/Issue26Test.php index 3313c3ec6..06cd63883 100644 --- a/tests/VObject/Recur/EventIterator/Issue26Test.php +++ b/tests/VObject/Recur/EventIterator/Issue26Test.php @@ -10,7 +10,7 @@ class Issue26Test extends TestCase { - public function testExpand() + public function testExpand(): void { $this->expectException(InvalidDataException::class); $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $it = new EventIterator($vcal, 'bae5d57a98'); + new EventIterator($vcal, 'bae5d57a98'); } } diff --git a/tests/VObject/Recur/EventIterator/Issue48Test.php b/tests/VObject/Recur/EventIterator/Issue48Test.php index aef592590..d2b809365 100644 --- a/tests/VObject/Recur/EventIterator/Issue48Test.php +++ b/tests/VObject/Recur/EventIterator/Issue48Test.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -11,7 +9,7 @@ class Issue48Test extends TestCase { - public function testExpand() + public function testExpand(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); $it = new EventIterator($vcal, 'foo'); $result = iterator_to_array($it); - $tz = new DateTimeZone('Europe/Moscow'); + $tz = new \DateTimeZone('Europe/Moscow'); $expected = [ - new DateTimeImmutable('2013-07-10 11:00:00', $tz), - new DateTimeImmutable('2013-07-12 11:00:00', $tz), - new DateTimeImmutable('2013-07-13 11:00:00', $tz), + new \DateTimeImmutable('2013-07-10 11:00:00', $tz), + new \DateTimeImmutable('2013-07-12 11:00:00', $tz), + new \DateTimeImmutable('2013-07-13 11:00:00', $tz), ]; - $this->assertEquals($expected, $result); + self::assertEquals($expected, $result); } } diff --git a/tests/VObject/Recur/EventIterator/Issue50Test.php b/tests/VObject/Recur/EventIterator/Issue50Test.php index 5c476e6f2..ec05de1b1 100644 --- a/tests/VObject/Recur/EventIterator/Issue50Test.php +++ b/tests/VObject/Recur/EventIterator/Issue50Test.php @@ -2,8 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -11,7 +9,7 @@ class Issue50Test extends TestCase { - public function testExpand() + public function testExpand(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); $it = new EventIterator($vcal, '1aef0b27-3d92-4581-829a-11999dd36724'); @@ -114,14 +112,14 @@ public function testExpand() $result[] = $instance; } - $tz = new DateTimeZone('Europe/Brussels'); + $tz = new \DateTimeZone('Europe/Brussels'); - $this->assertEquals([ - new DateTimeImmutable('2013-07-15 09:00:00', $tz), - new DateTimeImmutable('2013-07-16 07:00:00', $tz), - new DateTimeImmutable('2013-07-17 07:00:00', $tz), - new DateTimeImmutable('2013-07-18 09:00:00', $tz), - new DateTimeImmutable('2013-07-19 07:00:00', $tz), + self::assertEquals([ + new \DateTimeImmutable('2013-07-15 09:00:00', $tz), + new \DateTimeImmutable('2013-07-16 07:00:00', $tz), + new \DateTimeImmutable('2013-07-17 07:00:00', $tz), + new \DateTimeImmutable('2013-07-18 09:00:00', $tz), + new \DateTimeImmutable('2013-07-19 07:00:00', $tz), ], $result); } } diff --git a/tests/VObject/Recur/EventIterator/MainTest.php b/tests/VObject/Recur/EventIterator/MainTest.php index 9350080e4..022df4a3b 100644 --- a/tests/VObject/Recur/EventIterator/MainTest.php +++ b/tests/VObject/Recur/EventIterator/MainTest.php @@ -2,23 +2,32 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; +use Sabre\VObject\Component\VEvent; use Sabre\VObject\InvalidDataException; +use Sabre\VObject\Property\ICalendar\DateTime; use Sabre\VObject\Recur\EventIterator; +use Sabre\VObject\Recur\MaxInstancesExceededException; +use Sabre\VObject\Recur\NoInstancesException; class MainTest extends TestCase { - public function testValues() + /** + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws InvalidDataException + */ + public function testValues(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;BYHOUR=10;BYMINUTE=5;BYSECOND=16'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07')); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07')); $ev->add($dtStart); @@ -26,54 +35,73 @@ public function testValues() $it = new EventIterator($vcal, (string) $ev->UID); - $this->assertTrue($it->isInfinite()); + self::assertTrue($it->isInfinite()); } /** * @depends testValues + * + * @throws \Exception */ - public function testInvalidFreq() + public function testInvalidFreq(): void { $this->expectException(InvalidDataException::class); $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->RRULE = 'FREQ=SMONTHLY;INTERVAL=3;UNTIL=20111025T000000Z'; $ev->UID = 'foo'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); $vcal->add($ev); - $it = new EventIterator($vcal, (string) $ev->UID); + new EventIterator($vcal, (string) $ev->UID); } - public function testVCalendarNoUID() + /** + * @throws MaxInstancesExceededException + * @throws InvalidDataException + * @throws NoInstancesException + */ + public function testVCalendarNoUID(): void { $this->expectException(\InvalidArgumentException::class); $vcal = new VCalendar(); - $it = new EventIterator($vcal); + new EventIterator($vcal); } - public function testVCalendarInvalidUID() + /** + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws InvalidDataException + */ + public function testVCalendarInvalidUID(): void { $this->expectException(\InvalidArgumentException::class); $vcal = new VCalendar(); - $it = new EventIterator($vcal, 'foo'); + new EventIterator($vcal, 'foo'); } /** * @depends testValues + * + * @throws InvalidDataException + * @throws \Exception */ - public function testHourly() + public function testHourly(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=HOURLY;INTERVAL=3;UNTIL=20111025T000000Z'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07 12:00:00', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07 12:00:00', new \DateTimeZone('UTC'))); $ev->add($dtStart); $vcal->add($ev); @@ -92,22 +120,22 @@ public function testHourly() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07 12:00:00', $tz), - new DateTimeImmutable('2011-10-07 15:00:00', $tz), - new DateTimeImmutable('2011-10-07 18:00:00', $tz), - new DateTimeImmutable('2011-10-07 21:00:00', $tz), - new DateTimeImmutable('2011-10-08 00:00:00', $tz), - new DateTimeImmutable('2011-10-08 03:00:00', $tz), - new DateTimeImmutable('2011-10-08 06:00:00', $tz), - new DateTimeImmutable('2011-10-08 09:00:00', $tz), - new DateTimeImmutable('2011-10-08 12:00:00', $tz), - new DateTimeImmutable('2011-10-08 15:00:00', $tz), - new DateTimeImmutable('2011-10-08 18:00:00', $tz), - new DateTimeImmutable('2011-10-08 21:00:00', $tz), + new \DateTimeImmutable('2011-10-07 12:00:00', $tz), + new \DateTimeImmutable('2011-10-07 15:00:00', $tz), + new \DateTimeImmutable('2011-10-07 18:00:00', $tz), + new \DateTimeImmutable('2011-10-07 21:00:00', $tz), + new \DateTimeImmutable('2011-10-08 00:00:00', $tz), + new \DateTimeImmutable('2011-10-08 03:00:00', $tz), + new \DateTimeImmutable('2011-10-08 06:00:00', $tz), + new \DateTimeImmutable('2011-10-08 09:00:00', $tz), + new \DateTimeImmutable('2011-10-08 12:00:00', $tz), + new \DateTimeImmutable('2011-10-08 15:00:00', $tz), + new \DateTimeImmutable('2011-10-08 18:00:00', $tz), + new \DateTimeImmutable('2011-10-08 21:00:00', $tz), ], $result ); @@ -115,16 +143,23 @@ public function testHourly() /** * @depends testValues + * + * @throws InvalidDataException + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws \Exception */ - public function testDaily() + public function testDaily(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -144,17 +179,17 @@ public function testDaily() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07', $tz), - new DateTimeImmutable('2011-10-10', $tz), - new DateTimeImmutable('2011-10-13', $tz), - new DateTimeImmutable('2011-10-16', $tz), - new DateTimeImmutable('2011-10-19', $tz), - new DateTimeImmutable('2011-10-22', $tz), - new DateTimeImmutable('2011-10-25', $tz), + new \DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2011-10-10', $tz), + new \DateTimeImmutable('2011-10-13', $tz), + new \DateTimeImmutable('2011-10-16', $tz), + new \DateTimeImmutable('2011-10-19', $tz), + new \DateTimeImmutable('2011-10-22', $tz), + new \DateTimeImmutable('2011-10-25', $tz), ], $result ); @@ -163,14 +198,14 @@ public function testDaily() /** * @depends testValues */ - public function testNoRRULE() + public function testNoRRULE(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -190,11 +225,11 @@ public function testNoRRULE() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2011-10-07', $tz), ], $result ); @@ -203,7 +238,7 @@ public function testNoRRULE() /** * @depends testValues */ - public function testDailyByDayByHour() + public function testDailyByDayByHour(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -211,7 +246,7 @@ public function testDailyByDayByHour() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-08 06:00:00', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-08 06:00:00', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -231,22 +266,22 @@ public function testDailyByDayByHour() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-08 06:00:00', $tz), - new DateTimeImmutable('2011-10-08 07:00:00', $tz), - new DateTimeImmutable('2011-10-09 06:00:00', $tz), - new DateTimeImmutable('2011-10-09 07:00:00', $tz), - new DateTimeImmutable('2011-10-15 06:00:00', $tz), - new DateTimeImmutable('2011-10-15 07:00:00', $tz), - new DateTimeImmutable('2011-10-16 06:00:00', $tz), - new DateTimeImmutable('2011-10-16 07:00:00', $tz), - new DateTimeImmutable('2011-10-22 06:00:00', $tz), - new DateTimeImmutable('2011-10-22 07:00:00', $tz), - new DateTimeImmutable('2011-10-23 06:00:00', $tz), - new DateTimeImmutable('2011-10-23 07:00:00', $tz), + new \DateTimeImmutable('2011-10-08 06:00:00', $tz), + new \DateTimeImmutable('2011-10-08 07:00:00', $tz), + new \DateTimeImmutable('2011-10-09 06:00:00', $tz), + new \DateTimeImmutable('2011-10-09 07:00:00', $tz), + new \DateTimeImmutable('2011-10-15 06:00:00', $tz), + new \DateTimeImmutable('2011-10-15 07:00:00', $tz), + new \DateTimeImmutable('2011-10-16 06:00:00', $tz), + new \DateTimeImmutable('2011-10-16 07:00:00', $tz), + new \DateTimeImmutable('2011-10-22 06:00:00', $tz), + new \DateTimeImmutable('2011-10-22 07:00:00', $tz), + new \DateTimeImmutable('2011-10-23 06:00:00', $tz), + new \DateTimeImmutable('2011-10-23 07:00:00', $tz), ], $result ); @@ -255,7 +290,7 @@ public function testDailyByDayByHour() /** * @depends testValues */ - public function testDailyByHour() + public function testDailyByHour(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -263,7 +298,7 @@ public function testDailyByHour() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2012-10-11 12:00:00', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2012-10-11 12:00:00', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -283,22 +318,22 @@ public function testDailyByHour() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2012-10-11 12:00:00', $tz), - new DateTimeImmutable('2012-10-11 13:00:00', $tz), - new DateTimeImmutable('2012-10-11 14:00:00', $tz), - new DateTimeImmutable('2012-10-11 15:00:00', $tz), - new DateTimeImmutable('2012-10-13 10:00:00', $tz), - new DateTimeImmutable('2012-10-13 11:00:00', $tz), - new DateTimeImmutable('2012-10-13 12:00:00', $tz), - new DateTimeImmutable('2012-10-13 13:00:00', $tz), - new DateTimeImmutable('2012-10-13 14:00:00', $tz), - new DateTimeImmutable('2012-10-13 15:00:00', $tz), - new DateTimeImmutable('2012-10-15 10:00:00', $tz), - new DateTimeImmutable('2012-10-15 11:00:00', $tz), + new \DateTimeImmutable('2012-10-11 12:00:00', $tz), + new \DateTimeImmutable('2012-10-11 13:00:00', $tz), + new \DateTimeImmutable('2012-10-11 14:00:00', $tz), + new \DateTimeImmutable('2012-10-11 15:00:00', $tz), + new \DateTimeImmutable('2012-10-13 10:00:00', $tz), + new \DateTimeImmutable('2012-10-13 11:00:00', $tz), + new \DateTimeImmutable('2012-10-13 12:00:00', $tz), + new \DateTimeImmutable('2012-10-13 13:00:00', $tz), + new \DateTimeImmutable('2012-10-13 14:00:00', $tz), + new \DateTimeImmutable('2012-10-13 15:00:00', $tz), + new \DateTimeImmutable('2012-10-15 10:00:00', $tz), + new \DateTimeImmutable('2012-10-15 11:00:00', $tz), ], $result ); @@ -307,7 +342,7 @@ public function testDailyByHour() /** * @depends testValues */ - public function testDailyByDay() + public function testDailyByDay(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -315,7 +350,7 @@ public function testDailyByDay() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -335,22 +370,22 @@ public function testDailyByDay() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07', $tz), - new DateTimeImmutable('2011-10-11', $tz), - new DateTimeImmutable('2011-10-19', $tz), - new DateTimeImmutable('2011-10-21', $tz), - new DateTimeImmutable('2011-10-25', $tz), - new DateTimeImmutable('2011-11-02', $tz), - new DateTimeImmutable('2011-11-04', $tz), - new DateTimeImmutable('2011-11-08', $tz), - new DateTimeImmutable('2011-11-16', $tz), - new DateTimeImmutable('2011-11-18', $tz), - new DateTimeImmutable('2011-11-22', $tz), - new DateTimeImmutable('2011-11-30', $tz), + new \DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2011-10-11', $tz), + new \DateTimeImmutable('2011-10-19', $tz), + new \DateTimeImmutable('2011-10-21', $tz), + new \DateTimeImmutable('2011-10-25', $tz), + new \DateTimeImmutable('2011-11-02', $tz), + new \DateTimeImmutable('2011-11-04', $tz), + new \DateTimeImmutable('2011-11-08', $tz), + new \DateTimeImmutable('2011-11-16', $tz), + new \DateTimeImmutable('2011-11-18', $tz), + new \DateTimeImmutable('2011-11-22', $tz), + new \DateTimeImmutable('2011-11-30', $tz), ], $result ); @@ -359,7 +394,7 @@ public function testDailyByDay() /** * @depends testValues */ - public function testWeekly() + public function testWeekly(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -367,7 +402,7 @@ public function testWeekly() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;COUNT=10'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -387,20 +422,20 @@ public function testWeekly() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07', $tz), - new DateTimeImmutable('2011-10-21', $tz), - new DateTimeImmutable('2011-11-04', $tz), - new DateTimeImmutable('2011-11-18', $tz), - new DateTimeImmutable('2011-12-02', $tz), - new DateTimeImmutable('2011-12-16', $tz), - new DateTimeImmutable('2011-12-30', $tz), - new DateTimeImmutable('2012-01-13', $tz), - new DateTimeImmutable('2012-01-27', $tz), - new DateTimeImmutable('2012-02-10', $tz), + new \DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2011-10-21', $tz), + new \DateTimeImmutable('2011-11-04', $tz), + new \DateTimeImmutable('2011-11-18', $tz), + new \DateTimeImmutable('2011-12-02', $tz), + new \DateTimeImmutable('2011-12-16', $tz), + new \DateTimeImmutable('2011-12-30', $tz), + new \DateTimeImmutable('2012-01-13', $tz), + new \DateTimeImmutable('2012-01-27', $tz), + new \DateTimeImmutable('2012-02-10', $tz), ], $result ); @@ -409,7 +444,7 @@ public function testWeekly() /** * @depends testValues */ - public function testWeeklyByDayByHour() + public function testWeeklyByDayByHour(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -417,7 +452,7 @@ public function testWeeklyByDayByHour() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07 08:00:00', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07 08:00:00', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -437,25 +472,25 @@ public function testWeeklyByDayByHour() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07 08:00:00', $tz), - new DateTimeImmutable('2011-10-07 09:00:00', $tz), - new DateTimeImmutable('2011-10-07 10:00:00', $tz), - new DateTimeImmutable('2011-10-18 08:00:00', $tz), - new DateTimeImmutable('2011-10-18 09:00:00', $tz), - new DateTimeImmutable('2011-10-18 10:00:00', $tz), - new DateTimeImmutable('2011-10-19 08:00:00', $tz), - new DateTimeImmutable('2011-10-19 09:00:00', $tz), - new DateTimeImmutable('2011-10-19 10:00:00', $tz), - new DateTimeImmutable('2011-10-21 08:00:00', $tz), - new DateTimeImmutable('2011-10-21 09:00:00', $tz), - new DateTimeImmutable('2011-10-21 10:00:00', $tz), - new DateTimeImmutable('2011-11-01 08:00:00', $tz), - new DateTimeImmutable('2011-11-01 09:00:00', $tz), - new DateTimeImmutable('2011-11-01 10:00:00', $tz), + new \DateTimeImmutable('2011-10-07 08:00:00', $tz), + new \DateTimeImmutable('2011-10-07 09:00:00', $tz), + new \DateTimeImmutable('2011-10-07 10:00:00', $tz), + new \DateTimeImmutable('2011-10-18 08:00:00', $tz), + new \DateTimeImmutable('2011-10-18 09:00:00', $tz), + new \DateTimeImmutable('2011-10-18 10:00:00', $tz), + new \DateTimeImmutable('2011-10-19 08:00:00', $tz), + new \DateTimeImmutable('2011-10-19 09:00:00', $tz), + new \DateTimeImmutable('2011-10-19 10:00:00', $tz), + new \DateTimeImmutable('2011-10-21 08:00:00', $tz), + new \DateTimeImmutable('2011-10-21 09:00:00', $tz), + new \DateTimeImmutable('2011-10-21 10:00:00', $tz), + new \DateTimeImmutable('2011-11-01 08:00:00', $tz), + new \DateTimeImmutable('2011-11-01 09:00:00', $tz), + new \DateTimeImmutable('2011-11-01 10:00:00', $tz), ], $result ); @@ -464,7 +499,7 @@ public function testWeeklyByDayByHour() /** * @depends testValues */ - public function testWeeklyByDaySpecificHour() + public function testWeeklyByDaySpecificHour(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -472,7 +507,7 @@ public function testWeeklyByDaySpecificHour() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07 18:00:00', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07 18:00:00', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -492,22 +527,22 @@ public function testWeeklyByDaySpecificHour() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07 18:00:00', $tz), - new DateTimeImmutable('2011-10-18 18:00:00', $tz), - new DateTimeImmutable('2011-10-19 18:00:00', $tz), - new DateTimeImmutable('2011-10-21 18:00:00', $tz), - new DateTimeImmutable('2011-11-01 18:00:00', $tz), - new DateTimeImmutable('2011-11-02 18:00:00', $tz), - new DateTimeImmutable('2011-11-04 18:00:00', $tz), - new DateTimeImmutable('2011-11-15 18:00:00', $tz), - new DateTimeImmutable('2011-11-16 18:00:00', $tz), - new DateTimeImmutable('2011-11-18 18:00:00', $tz), - new DateTimeImmutable('2011-11-29 18:00:00', $tz), - new DateTimeImmutable('2011-11-30 18:00:00', $tz), + new \DateTimeImmutable('2011-10-07 18:00:00', $tz), + new \DateTimeImmutable('2011-10-18 18:00:00', $tz), + new \DateTimeImmutable('2011-10-19 18:00:00', $tz), + new \DateTimeImmutable('2011-10-21 18:00:00', $tz), + new \DateTimeImmutable('2011-11-01 18:00:00', $tz), + new \DateTimeImmutable('2011-11-02 18:00:00', $tz), + new \DateTimeImmutable('2011-11-04 18:00:00', $tz), + new \DateTimeImmutable('2011-11-15 18:00:00', $tz), + new \DateTimeImmutable('2011-11-16 18:00:00', $tz), + new \DateTimeImmutable('2011-11-18 18:00:00', $tz), + new \DateTimeImmutable('2011-11-29 18:00:00', $tz), + new \DateTimeImmutable('2011-11-30 18:00:00', $tz), ], $result ); @@ -516,7 +551,7 @@ public function testWeeklyByDaySpecificHour() /** * @depends testValues */ - public function testWeeklyByDay() + public function testWeeklyByDay(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -524,7 +559,7 @@ public function testWeeklyByDay() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -544,22 +579,22 @@ public function testWeeklyByDay() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07', $tz), - new DateTimeImmutable('2011-10-18', $tz), - new DateTimeImmutable('2011-10-19', $tz), - new DateTimeImmutable('2011-10-21', $tz), - new DateTimeImmutable('2011-11-01', $tz), - new DateTimeImmutable('2011-11-02', $tz), - new DateTimeImmutable('2011-11-04', $tz), - new DateTimeImmutable('2011-11-15', $tz), - new DateTimeImmutable('2011-11-16', $tz), - new DateTimeImmutable('2011-11-18', $tz), - new DateTimeImmutable('2011-11-29', $tz), - new DateTimeImmutable('2011-11-30', $tz), + new \DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2011-10-18', $tz), + new \DateTimeImmutable('2011-10-19', $tz), + new \DateTimeImmutable('2011-10-21', $tz), + new \DateTimeImmutable('2011-11-01', $tz), + new \DateTimeImmutable('2011-11-02', $tz), + new \DateTimeImmutable('2011-11-04', $tz), + new \DateTimeImmutable('2011-11-15', $tz), + new \DateTimeImmutable('2011-11-16', $tz), + new \DateTimeImmutable('2011-11-18', $tz), + new \DateTimeImmutable('2011-11-29', $tz), + new \DateTimeImmutable('2011-11-30', $tz), ], $result ); @@ -568,7 +603,7 @@ public function testWeeklyByDay() /** * @depends testValues */ - public function testMonthly() + public function testMonthly(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -576,7 +611,7 @@ public function testMonthly() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=3;COUNT=5'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-12-05', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-12-05', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -595,15 +630,15 @@ public function testMonthly() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-12-05', $tz), - new DateTimeImmutable('2012-03-05', $tz), - new DateTimeImmutable('2012-06-05', $tz), - new DateTimeImmutable('2012-09-05', $tz), - new DateTimeImmutable('2012-12-05', $tz), + new \DateTimeImmutable('2011-12-05', $tz), + new \DateTimeImmutable('2012-03-05', $tz), + new \DateTimeImmutable('2012-06-05', $tz), + new \DateTimeImmutable('2012-09-05', $tz), + new \DateTimeImmutable('2012-12-05', $tz), ], $result ); @@ -612,7 +647,7 @@ public function testMonthly() /** * @depends testValues */ - public function testMonthlyEndOfMonth() + public function testMonthlyEndOfMonth(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -620,7 +655,7 @@ public function testMonthlyEndOfMonth() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=12'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-12-31', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-12-31', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -639,22 +674,22 @@ public function testMonthlyEndOfMonth() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-12-31', $tz), - new DateTimeImmutable('2012-08-31', $tz), - new DateTimeImmutable('2012-10-31', $tz), - new DateTimeImmutable('2012-12-31', $tz), - new DateTimeImmutable('2013-08-31', $tz), - new DateTimeImmutable('2013-10-31', $tz), - new DateTimeImmutable('2013-12-31', $tz), - new DateTimeImmutable('2014-08-31', $tz), - new DateTimeImmutable('2014-10-31', $tz), - new DateTimeImmutable('2014-12-31', $tz), - new DateTimeImmutable('2015-08-31', $tz), - new DateTimeImmutable('2015-10-31', $tz), + new \DateTimeImmutable('2011-12-31', $tz), + new \DateTimeImmutable('2012-08-31', $tz), + new \DateTimeImmutable('2012-10-31', $tz), + new \DateTimeImmutable('2012-12-31', $tz), + new \DateTimeImmutable('2013-08-31', $tz), + new \DateTimeImmutable('2013-10-31', $tz), + new \DateTimeImmutable('2013-12-31', $tz), + new \DateTimeImmutable('2014-08-31', $tz), + new \DateTimeImmutable('2014-10-31', $tz), + new \DateTimeImmutable('2014-12-31', $tz), + new \DateTimeImmutable('2015-08-31', $tz), + new \DateTimeImmutable('2015-10-31', $tz), ], $result ); @@ -662,16 +697,23 @@ public function testMonthlyEndOfMonth() /** * @depends testValues + * + * @throws InvalidDataException + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws \Exception */ - public function testMonthlyByMonthDay() + public function testMonthlyByMonthDay(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-01-01', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-01-01', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -690,19 +732,19 @@ public function testMonthlyByMonthDay() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-01-01', $tz), - new DateTimeImmutable('2011-01-25', $tz), - new DateTimeImmutable('2011-01-31', $tz), - new DateTimeImmutable('2011-06-01', $tz), - new DateTimeImmutable('2011-06-24', $tz), - new DateTimeImmutable('2011-11-01', $tz), - new DateTimeImmutable('2011-11-24', $tz), - new DateTimeImmutable('2012-04-01', $tz), - new DateTimeImmutable('2012-04-24', $tz), + new \DateTimeImmutable('2011-01-01', $tz), + new \DateTimeImmutable('2011-01-25', $tz), + new \DateTimeImmutable('2011-01-31', $tz), + new \DateTimeImmutable('2011-06-01', $tz), + new \DateTimeImmutable('2011-06-24', $tz), + new \DateTimeImmutable('2011-11-01', $tz), + new \DateTimeImmutable('2011-11-24', $tz), + new \DateTimeImmutable('2012-04-01', $tz), + new \DateTimeImmutable('2012-04-24', $tz), ], $result ); @@ -713,9 +755,10 @@ public function testMonthlyByMonthDay() * after 1 second. Would be good to optimize later. * * @depends testValues + * * @medium */ - public function testMonthlyByDay() + public function testMonthlyByDay(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -723,7 +766,7 @@ public function testMonthlyByDay() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-01-03', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-01-03', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -742,26 +785,26 @@ public function testMonthlyByDay() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-01-03', $tz), - new DateTimeImmutable('2011-01-05', $tz), - new DateTimeImmutable('2011-01-10', $tz), - new DateTimeImmutable('2011-01-17', $tz), - new DateTimeImmutable('2011-01-18', $tz), - new DateTimeImmutable('2011-01-20', $tz), - new DateTimeImmutable('2011-01-24', $tz), - new DateTimeImmutable('2011-01-31', $tz), - new DateTimeImmutable('2011-03-02', $tz), - new DateTimeImmutable('2011-03-07', $tz), - new DateTimeImmutable('2011-03-14', $tz), - new DateTimeImmutable('2011-03-17', $tz), - new DateTimeImmutable('2011-03-21', $tz), - new DateTimeImmutable('2011-03-22', $tz), - new DateTimeImmutable('2011-03-28', $tz), - new DateTimeImmutable('2011-05-02', $tz), + new \DateTimeImmutable('2011-01-03', $tz), + new \DateTimeImmutable('2011-01-05', $tz), + new \DateTimeImmutable('2011-01-10', $tz), + new \DateTimeImmutable('2011-01-17', $tz), + new \DateTimeImmutable('2011-01-18', $tz), + new \DateTimeImmutable('2011-01-20', $tz), + new \DateTimeImmutable('2011-01-24', $tz), + new \DateTimeImmutable('2011-01-31', $tz), + new \DateTimeImmutable('2011-03-02', $tz), + new \DateTimeImmutable('2011-03-07', $tz), + new \DateTimeImmutable('2011-03-14', $tz), + new \DateTimeImmutable('2011-03-17', $tz), + new \DateTimeImmutable('2011-03-21', $tz), + new \DateTimeImmutable('2011-03-22', $tz), + new \DateTimeImmutable('2011-03-28', $tz), + new \DateTimeImmutable('2011-05-02', $tz), ], $result ); @@ -770,7 +813,7 @@ public function testMonthlyByDay() /** * @depends testValues */ - public function testMonthlyByDayByMonthDay() + public function testMonthlyByDayByMonthDay(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -778,7 +821,7 @@ public function testMonthlyByDayByMonthDay() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-08-01', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-08-01', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -797,20 +840,20 @@ public function testMonthlyByDayByMonthDay() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-08-01', $tz), - new DateTimeImmutable('2012-10-01', $tz), - new DateTimeImmutable('2013-04-01', $tz), - new DateTimeImmutable('2013-07-01', $tz), - new DateTimeImmutable('2014-09-01', $tz), - new DateTimeImmutable('2014-12-01', $tz), - new DateTimeImmutable('2015-06-01', $tz), - new DateTimeImmutable('2016-02-01', $tz), - new DateTimeImmutable('2016-08-01', $tz), - new DateTimeImmutable('2017-05-01', $tz), + new \DateTimeImmutable('2011-08-01', $tz), + new \DateTimeImmutable('2012-10-01', $tz), + new \DateTimeImmutable('2013-04-01', $tz), + new \DateTimeImmutable('2013-07-01', $tz), + new \DateTimeImmutable('2014-09-01', $tz), + new \DateTimeImmutable('2014-12-01', $tz), + new \DateTimeImmutable('2015-06-01', $tz), + new \DateTimeImmutable('2016-02-01', $tz), + new \DateTimeImmutable('2016-08-01', $tz), + new \DateTimeImmutable('2017-05-01', $tz), ], $result ); @@ -819,7 +862,7 @@ public function testMonthlyByDayByMonthDay() /** * @depends testValues */ - public function testMonthlyByDayBySetPos() + public function testMonthlyByDayBySetPos(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -827,7 +870,7 @@ public function testMonthlyByDayBySetPos() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-01-03', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-01-03', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -846,20 +889,20 @@ public function testMonthlyByDayBySetPos() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-01-03', $tz), - new DateTimeImmutable('2011-01-31', $tz), - new DateTimeImmutable('2011-02-01', $tz), - new DateTimeImmutable('2011-02-28', $tz), - new DateTimeImmutable('2011-03-01', $tz), - new DateTimeImmutable('2011-03-31', $tz), - new DateTimeImmutable('2011-04-01', $tz), - new DateTimeImmutable('2011-04-29', $tz), - new DateTimeImmutable('2011-05-02', $tz), - new DateTimeImmutable('2011-05-31', $tz), + new \DateTimeImmutable('2011-01-03', $tz), + new \DateTimeImmutable('2011-01-31', $tz), + new \DateTimeImmutable('2011-02-01', $tz), + new \DateTimeImmutable('2011-02-28', $tz), + new \DateTimeImmutable('2011-03-01', $tz), + new \DateTimeImmutable('2011-03-31', $tz), + new \DateTimeImmutable('2011-04-01', $tz), + new \DateTimeImmutable('2011-04-29', $tz), + new \DateTimeImmutable('2011-05-02', $tz), + new \DateTimeImmutable('2011-05-31', $tz), ], $result ); @@ -867,16 +910,21 @@ public function testMonthlyByDayBySetPos() /** * @depends testValues + * + * @throws InvalidDataException + * @throws \Exception */ - public function testYearly() + public function testYearly(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=10;INTERVAL=3'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-01-01', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-01-01', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -895,20 +943,20 @@ public function testYearly() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-01-01', $tz), - new DateTimeImmutable('2014-01-01', $tz), - new DateTimeImmutable('2017-01-01', $tz), - new DateTimeImmutable('2020-01-01', $tz), - new DateTimeImmutable('2023-01-01', $tz), - new DateTimeImmutable('2026-01-01', $tz), - new DateTimeImmutable('2029-01-01', $tz), - new DateTimeImmutable('2032-01-01', $tz), - new DateTimeImmutable('2035-01-01', $tz), - new DateTimeImmutable('2038-01-01', $tz), + new \DateTimeImmutable('2011-01-01', $tz), + new \DateTimeImmutable('2014-01-01', $tz), + new \DateTimeImmutable('2017-01-01', $tz), + new \DateTimeImmutable('2020-01-01', $tz), + new \DateTimeImmutable('2023-01-01', $tz), + new \DateTimeImmutable('2026-01-01', $tz), + new \DateTimeImmutable('2029-01-01', $tz), + new \DateTimeImmutable('2032-01-01', $tz), + new \DateTimeImmutable('2035-01-01', $tz), + new \DateTimeImmutable('2038-01-01', $tz), ], $result ); @@ -917,7 +965,7 @@ public function testYearly() /** * @depends testValues */ - public function testYearlyLeapYear() + public function testYearlyLeapYear(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -925,7 +973,7 @@ public function testYearlyLeapYear() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=3'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2012-02-29', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2012-02-29', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -944,13 +992,13 @@ public function testYearlyLeapYear() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2012-02-29', $tz), - new DateTimeImmutable('2016-02-29', $tz), - new DateTimeImmutable('2020-02-29', $tz), + new \DateTimeImmutable('2012-02-29', $tz), + new \DateTimeImmutable('2016-02-29', $tz), + new \DateTimeImmutable('2020-02-29', $tz), ], $result ); @@ -959,7 +1007,7 @@ public function testYearlyLeapYear() /** * @depends testValues */ - public function testYearlyByMonth() + public function testYearlyByMonth(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -967,7 +1015,7 @@ public function testYearlyByMonth() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-04-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-04-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -986,18 +1034,18 @@ public function testYearlyByMonth() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-04-07', $tz), - new DateTimeImmutable('2011-10-07', $tz), - new DateTimeImmutable('2015-04-07', $tz), - new DateTimeImmutable('2015-10-07', $tz), - new DateTimeImmutable('2019-04-07', $tz), - new DateTimeImmutable('2019-10-07', $tz), - new DateTimeImmutable('2023-04-07', $tz), - new DateTimeImmutable('2023-10-07', $tz), + new \DateTimeImmutable('2011-04-07', $tz), + new \DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2015-04-07', $tz), + new \DateTimeImmutable('2015-10-07', $tz), + new \DateTimeImmutable('2019-04-07', $tz), + new \DateTimeImmutable('2019-10-07', $tz), + new \DateTimeImmutable('2023-04-07', $tz), + new \DateTimeImmutable('2023-10-07', $tz), ], $result ); @@ -1006,7 +1054,7 @@ public function testYearlyByMonth() /** * @depends testValues */ - public function testYearlyByMonthByDay() + public function testYearlyByMonthByDay(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -1014,7 +1062,7 @@ public function testYearlyByMonthByDay() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-04-04', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-04-04', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -1033,18 +1081,18 @@ public function testYearlyByMonthByDay() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-04-04', $tz), - new DateTimeImmutable('2011-04-24', $tz), - new DateTimeImmutable('2011-10-03', $tz), - new DateTimeImmutable('2011-10-30', $tz), - new DateTimeImmutable('2016-04-04', $tz), - new DateTimeImmutable('2016-04-24', $tz), - new DateTimeImmutable('2016-10-03', $tz), - new DateTimeImmutable('2016-10-30', $tz), + new \DateTimeImmutable('2011-04-04', $tz), + new \DateTimeImmutable('2011-04-24', $tz), + new \DateTimeImmutable('2011-10-03', $tz), + new \DateTimeImmutable('2011-10-30', $tz), + new \DateTimeImmutable('2016-04-04', $tz), + new \DateTimeImmutable('2016-04-24', $tz), + new \DateTimeImmutable('2016-10-03', $tz), + new \DateTimeImmutable('2016-10-30', $tz), ], $result ); @@ -1053,7 +1101,7 @@ public function testYearlyByMonthByDay() /** * @depends testValues */ - public function testFastForward() + public function testFastForward(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -1061,7 +1109,7 @@ public function testFastForward() $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-04-04', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-04-04', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -1071,7 +1119,7 @@ public function testFastForward() // The idea is that we're fast-forwarding too far in the future, so // there will be no results left. - $it->fastForward(new DateTimeImmutable('2020-05-05', new DateTimeZone('UTC'))); + $it->fastForward(new \DateTimeImmutable('2020-05-05', new \DateTimeZone('UTC'))); $max = 20; $result = []; @@ -1085,13 +1133,13 @@ public function testFastForward() $it->next(); } - $this->assertEquals([], $result); + self::assertEquals([], $result); } /** * @depends testValues */ - public function testFastForwardAllDayEventThatStopAtTheStartTime() + public function testFastForwardAllDayEventThatStopAtTheStartTime(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); @@ -1100,41 +1148,50 @@ public function testFastForwardAllDayEventThatStopAtTheStartTime() $ev->RRULE = 'FREQ=DAILY'; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-04-04', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-04-04', new \DateTimeZone('UTC'))); $ev->add($dtStart); $dtEnd = $vcal->createProperty('DTSTART'); - $dtEnd->setDateTime(new DateTimeImmutable('2011-04-05', new DateTimeZone('UTC'))); + $dtEnd->setDateTime(new \DateTimeImmutable('2011-04-05', new \DateTimeZone('UTC'))); $ev->add($dtEnd); $vcal->add($ev); $it = new EventIterator($vcal, (string) $ev->UID); - $it->fastForward(new DateTimeImmutable('2011-04-05T000000', new DateTimeZone('UTC'))); + $it->fastForward(new \DateTimeImmutable('2011-04-05T000000', new \DateTimeZone('UTC'))); - $this->assertEquals(new DateTimeImmutable('2011-04-06'), $it->getDTStart()); + self::assertEquals(new \DateTimeImmutable('2011-04-06'), $it->getDTStart()); } /** * @depends testValues + * + * @throws InvalidDataException + * @throws MaxInstancesExceededException + * @throws NoInstancesException + * @throws \Exception */ - public function testComplexExclusions() + public function testComplexExclusions(): void { $vcal = new VCalendar(); + /** @var VEvent $ev */ $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RRULE = 'FREQ=YEARLY;COUNT=10'; + /** @var DateTime $dtStart */ $dtStart = $vcal->createProperty('DTSTART'); - $tz = new DateTimeZone('Canada/Eastern'); - $dtStart->setDateTime(new DateTimeImmutable('2011-01-01 13:50:20', $tz)); + $tz = new \DateTimeZone('Canada/Eastern'); + $dtStart->setDateTime(new \DateTimeImmutable('2011-01-01 13:50:20', $tz)); + /** @var DateTime $exDate1 */ $exDate1 = $vcal->createProperty('EXDATE'); - $exDate1->setDateTimes([new DateTimeImmutable('2012-01-01 13:50:20', $tz), new DateTimeImmutable('2014-01-01 13:50:20', $tz)]); + $exDate1->setDateTimes([new \DateTimeImmutable('2012-01-01 13:50:20', $tz), new \DateTimeImmutable('2014-01-01 13:50:20', $tz)]); + /** @var DateTime $exDate2 */ $exDate2 = $vcal->createProperty('EXDATE'); - $exDate2->setDateTimes([new DateTimeImmutable('2016-01-01 13:50:20', $tz)]); + $exDate2->setDateTimes([new \DateTimeImmutable('2016-01-01 13:50:20', $tz)]); $ev->add($dtStart); $ev->add($exDate1); @@ -1155,15 +1212,15 @@ public function testComplexExclusions() } } - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-01-01 13:50:20', $tz), - new DateTimeImmutable('2013-01-01 13:50:20', $tz), - new DateTimeImmutable('2015-01-01 13:50:20', $tz), - new DateTimeImmutable('2017-01-01 13:50:20', $tz), - new DateTimeImmutable('2018-01-01 13:50:20', $tz), - new DateTimeImmutable('2019-01-01 13:50:20', $tz), - new DateTimeImmutable('2020-01-01 13:50:20', $tz), + new \DateTimeImmutable('2011-01-01 13:50:20', $tz), + new \DateTimeImmutable('2013-01-01 13:50:20', $tz), + new \DateTimeImmutable('2015-01-01 13:50:20', $tz), + new \DateTimeImmutable('2017-01-01 13:50:20', $tz), + new \DateTimeImmutable('2018-01-01 13:50:20', $tz), + new \DateTimeImmutable('2019-01-01 13:50:20', $tz), + new \DateTimeImmutable('2020-01-01 13:50:20', $tz), ], $result ); @@ -1172,7 +1229,7 @@ public function testComplexExclusions() /** * @depends testValues */ - public function testOverriddenEvent() + public function testOverriddenEvent(): void { $vcal = new VCalendar(); @@ -1212,21 +1269,21 @@ public function testOverriddenEvent() $it->next(); } - $tz = new DateTimeZone('UTC'); - $this->assertEquals([ - new DateTimeImmutable('2012-01-07 12:00:00', $tz), - new DateTimeImmutable('2012-01-08 12:00:00', $tz), - new DateTimeImmutable('2012-01-09 12:00:00', $tz), - new DateTimeImmutable('2012-01-10 14:00:00', $tz), - new DateTimeImmutable('2012-01-11 12:00:00', $tz), - new DateTimeImmutable('2012-01-12 12:00:00', $tz), - new DateTimeImmutable('2012-01-14 12:00:00', $tz), - new DateTimeImmutable('2012-01-15 12:00:00', $tz), - new DateTimeImmutable('2012-01-15 14:00:00', $tz), - new DateTimeImmutable('2012-01-16 12:00:00', $tz), + $tz = new \DateTimeZone('UTC'); + self::assertEquals([ + new \DateTimeImmutable('2012-01-07 12:00:00', $tz), + new \DateTimeImmutable('2012-01-08 12:00:00', $tz), + new \DateTimeImmutable('2012-01-09 12:00:00', $tz), + new \DateTimeImmutable('2012-01-10 14:00:00', $tz), + new \DateTimeImmutable('2012-01-11 12:00:00', $tz), + new \DateTimeImmutable('2012-01-12 12:00:00', $tz), + new \DateTimeImmutable('2012-01-14 12:00:00', $tz), + new \DateTimeImmutable('2012-01-15 12:00:00', $tz), + new \DateTimeImmutable('2012-01-15 14:00:00', $tz), + new \DateTimeImmutable('2012-01-16 12:00:00', $tz), ], $dates); - $this->assertEquals([ + self::assertEquals([ 'baseEvent', 'baseEvent', 'baseEvent', @@ -1243,7 +1300,7 @@ public function testOverriddenEvent() /** * @depends testValues */ - public function testOverriddenEvent2() + public function testOverriddenEvent2(): void { $vcal = new VCalendar(); @@ -1274,14 +1331,14 @@ public function testOverriddenEvent2() $it->next(); } - $tz = new DateTimeZone('UTC'); - $this->assertEquals([ - new DateTimeImmutable('2012-01-12 12:00:00', $tz), - new DateTimeImmutable('2012-01-13 12:00:00', $tz), - new DateTimeImmutable('2012-01-26 12:00:00', $tz), + $tz = new \DateTimeZone('UTC'); + self::assertEquals([ + new \DateTimeImmutable('2012-01-12 12:00:00', $tz), + new \DateTimeImmutable('2012-01-13 12:00:00', $tz), + new \DateTimeImmutable('2012-01-26 12:00:00', $tz), ], $dates); - $this->assertEquals([ + self::assertEquals([ 'baseEvent', 'Override!', 'baseEvent', @@ -1291,7 +1348,7 @@ public function testOverriddenEvent2() /** * @depends testValues */ - public function testOverriddenEventNoValuesExpected() + public function testOverriddenEventNoValuesExpected(): void { $vcal = new VCalendar(); $ev1 = $vcal->createComponent('VEVENT'); @@ -1320,36 +1377,36 @@ public function testOverriddenEventNoValuesExpected() // The reported problem was specifically related to the VCALENDAR // expansion. In this particular case, we had to forward to the 28th of // january. - $it->fastForward(new DateTimeImmutable('2012-01-28 23:00:00')); + $it->fastForward(new \DateTimeImmutable('2012-01-28 23:00:00')); // We stop the loop when it hits the 6th of February. Normally this // iterator would hit 24, 25 (overridden from 31) and 7 feb but because // we 'filter' from the 28th till the 6th, we should get 0 results. - while ($it->valid() && $it->getDTStart() < new DateTimeImmutable('2012-02-06 23:00:00')) { + while ($it->valid() && $it->getDTStart() < new \DateTimeImmutable('2012-02-06 23:00:00')) { $dates[] = $it->getDTStart(); $summaries[] = (string) $it->getEventObject()->SUMMARY; $it->next(); } - $this->assertEquals([], $dates); - $this->assertEquals([], $summaries); + self::assertEquals([], $dates); + self::assertEquals([], $summaries); } /** * @depends testValues */ - public function testRDATE() + public function testRDATE(): void { $vcal = new VCalendar(); $ev = $vcal->createComponent('VEVENT'); $ev->UID = 'bla'; $ev->RDATE = [ - new DateTimeImmutable('2014-08-07', new DateTimeZone('UTC')), - new DateTimeImmutable('2014-08-08', new DateTimeZone('UTC')), + new \DateTimeImmutable('2014-08-07', new \DateTimeZone('UTC')), + new \DateTimeImmutable('2014-08-08', new \DateTimeZone('UTC')), ]; $dtStart = $vcal->createProperty('DTSTART'); - $dtStart->setDateTime(new DateTimeImmutable('2011-10-07', new DateTimeZone('UTC'))); + $dtStart->setDateTime(new \DateTimeImmutable('2011-10-07', new \DateTimeZone('UTC'))); $ev->add($dtStart); @@ -1369,13 +1426,13 @@ public function testRDATE() } } - $tz = new DateTimeZone('UTC'); + $tz = new \DateTimeZone('UTC'); - $this->assertEquals( + self::assertEquals( [ - new DateTimeImmutable('2011-10-07', $tz), - new DateTimeImmutable('2014-08-07', $tz), - new DateTimeImmutable('2014-08-08', $tz), + new \DateTimeImmutable('2011-10-07', $tz), + new \DateTimeImmutable('2014-08-07', $tz), + new \DateTimeImmutable('2014-08-08', $tz), ], $result ); @@ -1384,7 +1441,7 @@ public function testRDATE() /** * @depends testValues */ - public function testNoMasterBadUID() + public function testNoMasterBadUID(): void { $this->expectException(\InvalidArgumentException::class); $vcal = new VCalendar(); @@ -1406,6 +1463,6 @@ public function testNoMasterBadUID() $vcal->add($ev3); - $it = new EventIterator($vcal, 'broken'); + new EventIterator($vcal, 'broken'); } } diff --git a/tests/VObject/Recur/EventIterator/MaxInstancesTest.php b/tests/VObject/Recur/EventIterator/MaxInstancesTest.php index 6314b3b5a..19dca97af 100644 --- a/tests/VObject/Recur/EventIterator/MaxInstancesTest.php +++ b/tests/VObject/Recur/EventIterator/MaxInstancesTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\Reader; use Sabre\VObject\Recur\MaxInstancesExceededException; @@ -10,7 +9,7 @@ class MaxInstancesTest extends TestCase { - public function testExceedMaxRecurrences() + public function testExceedMaxRecurrences(): void { $this->expectException(MaxInstancesExceededException::class); $input = <<expand(new DateTime('2014-08-01'), new DateTime('2014-09-01')); + $vcal->expand(new \DateTime('2014-08-01'), new \DateTime('2014-09-01')); } finally { Settings::$maxRecurrences = $temp; } diff --git a/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php b/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php index 69af8a8a1..2b1656ecc 100644 --- a/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php +++ b/tests/VObject/Recur/EventIterator/MissingOverriddenTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\Component\VCalendar; use Sabre\VObject\Reader; @@ -11,7 +10,7 @@ class MissingOverriddenTest extends TestCase { use \Sabre\VObject\PHPUnitAssertions; - public function testExpand() + public function testExpand(): void { $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $vcal = $vcal->expand(new DateTime('2011-01-01'), new DateTime('2015-01-01')); + $vcal = $vcal->expand(new \DateTime('2011-01-01'), new \DateTime('2015-01-01')); $output = <<assertVObjectEqualsVObject($output, $vcal); + self::assertVObjectEqualsVObject($output, $vcal); } } diff --git a/tests/VObject/Recur/EventIterator/NoInstancesTest.php b/tests/VObject/Recur/EventIterator/NoInstancesTest.php index d89afd197..1eff5f94e 100644 --- a/tests/VObject/Recur/EventIterator/NoInstancesTest.php +++ b/tests/VObject/Recur/EventIterator/NoInstancesTest.php @@ -10,7 +10,7 @@ class NoInstancesTest extends TestCase { - public function testRecurrence() + public function testRecurrence(): void { $this->expectException(NoInstancesException::class); $input = <<assertInstanceOf(VCalendar::class, $vcal); + self::assertInstanceOf(VCalendar::class, $vcal); - $it = new EventIterator($vcal, 'foo'); + new EventIterator($vcal, 'foo'); } } diff --git a/tests/VObject/Recur/EventIterator/OverrideDurationTest.php b/tests/VObject/Recur/EventIterator/OverrideDurationTest.php index f25ef13d9..8162a6143 100644 --- a/tests/VObject/Recur/EventIterator/OverrideDurationTest.php +++ b/tests/VObject/Recur/EventIterator/OverrideDurationTest.php @@ -10,7 +10,7 @@ class OverrideDurationTest extends TestCase { use \Sabre\VObject\PHPUnitAssertions; - public function testOverrideDuration() + public function testOverrideDuration(): void { $ics = <<getComponents()); - $this->assertEquals($eventIterator->current()->format('Y-m-d H:i:s'), '2021-05-17 09:00:00', 'recur event start time'); - $this->assertEquals($eventIterator->getDtEnd()->format('Y-m-d H:i:s'), '2021-05-17 10:00:00', 'recur event end time'); + self::assertEquals('2021-05-17 09:00:00', $eventIterator->current()->format('Y-m-d H:i:s'), 'recur event start time'); + self::assertEquals('2021-05-17 10:00:00', $eventIterator->getDtEnd()->format('Y-m-d H:i:s'), 'recur event end time'); $eventIterator->next(); - $this->assertEquals($eventIterator->current()->format('Y-m-d H:i:s'), '2021-05-18 09:00:00', 'recur event start time'); - $this->assertEquals($eventIterator->getDtEnd()->format('Y-m-d H:i:s'), '2021-05-18 10:00:00', 'recur event end time'); + self::assertEquals('2021-05-18 09:00:00', $eventIterator->current()->format('Y-m-d H:i:s'), 'recur event start time'); + self::assertEquals('2021-05-18 10:00:00', $eventIterator->getDtEnd()->format('Y-m-d H:i:s'), 'recur event end time'); $eventIterator->next(); - $this->assertEquals($eventIterator->current()->format('Y-m-d H:i:s'), '2021-05-19 09:00:00', 'overridden event start time'); - $this->assertEquals($eventIterator->getDtEnd()->format('Y-m-d H:i:s'), '2021-05-19 12:00:00', 'overridden event end time'); + self::assertEquals('2021-05-19 09:00:00', $eventIterator->current()->format('Y-m-d H:i:s'), 'overridden event start time'); + self::assertEquals('2021-05-19 12:00:00', $eventIterator->getDtEnd()->format('Y-m-d H:i:s'), 'overridden event end time'); $eventIterator->next(); - $this->assertEquals($eventIterator->current()->format('Y-m-d H:i:s'), '2021-05-20 09:00:00', 'recur event start time'); - $this->assertEquals($eventIterator->getDtEnd()->format('Y-m-d H:i:s'), '2021-05-20 10:00:00', 'recur event end time'); + self::assertEquals('2021-05-20 09:00:00', $eventIterator->current()->format('Y-m-d H:i:s'), 'recur event start time'); + self::assertEquals('2021-05-20 10:00:00', $eventIterator->getDtEnd()->format('Y-m-d H:i:s'), 'recur event end time'); } } diff --git a/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php b/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php index 150a13980..15c92f04c 100644 --- a/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php +++ b/tests/VObject/Recur/EventIterator/OverrideFirstEventTest.php @@ -2,7 +2,6 @@ namespace Sabre\VObject\Recur\EventIterator; -use DateTime; use PHPUnit\Framework\TestCase; use Sabre\VObject\Reader; @@ -10,7 +9,7 @@ class OverrideFirstEventTest extends TestCase { use \Sabre\VObject\PHPUnitAssertions; - public function testOverrideFirstEvent() + public function testOverrideFirstEvent(): void { $input = <<expand(new DateTime('2014-08-01'), new DateTime('2014-09-01')); + $vcal = $vcal->expand(new \DateTime('2014-08-01'), new \DateTime('2014-09-01')); $expected = <<assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $vcal ); } - public function testRemoveFirstEvent() + public function testRemoveFirstEvent(): void { $input = <<expand(new DateTime('2014-08-01'), new DateTime('2014-08-19')); + $vcal = $vcal->expand(new \DateTime('2014-08-01'), new \DateTime('2014-08-19')); $expected = <<assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $expected, $vcal ); diff --git a/tests/VObject/Recur/EventIterator/SameDateForRecurringEventsTest.php b/tests/VObject/Recur/EventIterator/SameDateForRecurringEventsTest.php index 1cbd9792e..ef3ed9b12 100644 --- a/tests/VObject/Recur/EventIterator/SameDateForRecurringEventsTest.php +++ b/tests/VObject/Recur/EventIterator/SameDateForRecurringEventsTest.php @@ -16,7 +16,7 @@ class SameDateForRecurringEventsTest extends TestCase /** * Checking is all events iterated by EventIterator. */ - public function testAllEventsArePresentInIterator() + public function testAllEventsArePresentInIterator(): void { $ics = <<getComponents()); - $this->assertEquals(4, iterator_count($eventIterator), 'in ICS 4 events'); + self::assertEquals(4, iterator_count($eventIterator), 'in ICS 4 events'); } } diff --git a/tests/VObject/Recur/FastForwardBeforeTest.php b/tests/VObject/Recur/FastForwardBeforeTest.php index 3461bd6a5..0426cc5ec 100644 --- a/tests/VObject/Recur/FastForwardBeforeTest.php +++ b/tests/VObject/Recur/FastForwardBeforeTest.php @@ -2,13 +2,11 @@ namespace Sabre\VObject\Recur; -use DateTime; -use DateTimeZone; use PHPUnit\Framework\TestCase; class FastForwardBeforeTest extends TestCase { - const FF_TIMEOUT = 1000000; // in usec + public const FF_TIMEOUT = 1000000; // in usec private function fastForward(RRuleIterator $ruleIterator, \DateTimeInterface $ffDate) { @@ -22,16 +20,16 @@ private function fastForward(RRuleIterator $ruleIterator, \DateTimeInterface $ff public function testFastForwardBeforeYearlyBasic() { - $startDate = new DateTime('1970-10-23 00:00:00', new DateTimeZone('zulu')); - $ffDate = new DateTime('midnight', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(99999, 1, 1); $rrule = new RRuleIterator('FREQ=YEARLY', $startDate); $this->fastForward($rrule, $ffDate); $year = 60 * 60 * 24 * 365; - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(99998, 10, 23) ->setTime(0, 0, 0) ->getTimestamp(); @@ -86,7 +84,7 @@ public function testFastForwardBeforeYearlyBasic() public function testFastForwardBeforeYearlyByYearDay() { $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(99999, 1, 5); $rrule = new RRuleIterator('FREQ=YEARLY;BYYEARDAY=1,20,300', $startDate); @@ -94,8 +92,8 @@ public function testFastForwardBeforeYearlyByYearDay() // 1st day $day = 60 * 60 * 24; - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(99999, 1, 1) ->setTime(0, 0, 0) ->getTimestamp(); @@ -140,7 +138,7 @@ public function testFastForwardBeforeYearlyByYearDay() public function testFastForwardBeforeYearlyByWeekNo() { $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(99999, 1, 5); $rrule = new RRuleIterator('FREQ=YEARLY;BYWEEKNO=1,20', $startDate); @@ -150,8 +148,8 @@ public function testFastForwardBeforeYearlyByWeekNo() $week = 7 * $day; // 1st week - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(99999, 1, 4) ->setTime(0, 0, 0) ->getTimestamp(); @@ -166,13 +164,13 @@ public function testFastForwardBeforeYearlyByWeekNo() public function testFastForwardBeforeYearlyAdvanced() { $startDate = new \DateTime('1970-10-23 12:34:56', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(10000, 1, 2)->setTime(8, 44, 13); $rrule = new RRuleIterator('FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(10000, 1, 2) ->setTime(8, 30, 56) ->getTimestamp(); @@ -216,7 +214,7 @@ public function testFastForwardBeforeYearlyAdvanced() // jump to 6th january 10002 $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(10002, 1, 6) ->setTime(8, 30, 56) ->getTimestamp(); @@ -230,13 +228,13 @@ public function testFastForwardBeforeYearlyAdvanced() public function testFastForwardBeforeMonthlyBasic() { $startDate = new \DateTime('1970-10-23 22:42:31', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(18000, 1, 30); $rrule = new RRuleIterator('FREQ=MONTHLY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(18000, 1, 23) ->setTime(22, 42, 31) ->getTimestamp(); @@ -276,55 +274,55 @@ public function testFastForwardBeforeMonthly31thDay() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(18000, 2, 1); $rrule = new RRuleIterator('FREQ=MONTHLY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new \DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(18000, 1, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // march $rrule->next(); - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(18000, 3, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // may $rrule->next(); - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(18000, 5, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // july $rrule->next(); - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(18000, 7, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // august $rrule->next(); - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(18000, 8, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // october $rrule->next(); - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(18000, 10, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // december $rrule->next(); - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(18000, 12, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -333,8 +331,8 @@ public function testFastForwardBeforeMonthly31thDay() public function testFastForwardBeforeMonthlyAdvanced() { $timezone = 'America/New_York'; - $startDate = new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone)); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(8000, 1, 6); // every 2 months on the 1st Monday, 2nd Tuesday, 3rd Wednesday and 4th Thursday $rrule = new RRuleIterator('FREQ=MONTHLY;INTERVAL=2;BYDAY=1MO,2TU,3WE,4TH', $startDate); @@ -342,48 +340,48 @@ public function testFastForwardBeforeMonthlyAdvanced() $this->fastForward($rrule, $ffDate); // monday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 1, 3) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // tuesday - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 1, 11) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // wednesday - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 1, 19) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // thursday - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 1, 27) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // monday march - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 3, 6) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // tuesday - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 3, 14) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // wednesday (this month starts on wednesday so that's just the next day) - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 3, 15) ->getTimestamp(); $rrule->next(); @@ -391,7 +389,7 @@ public function testFastForwardBeforeMonthlyAdvanced() // thursday $expected += 8 * 24 * 60 * 60; - $expected = (new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone))) + $expected = (new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone))) ->setDate(8000, 3, 23) ->getTimestamp(); $rrule->next(); @@ -402,13 +400,13 @@ public function testFastForwardBeforeDailyBasic() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(4000, 1, 2); $rrule = new RRuleIterator('FREQ=DAILY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(4000, 1, 1) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -442,14 +440,14 @@ public function testFastForwardBeforeDailyAdvanced() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone($timezone)); + $ffDate = new \DateTime('midnight', new \DateTimeZone($timezone)); $ffDate->setDate(4000, 1, 4)->setTime(16, 30, 0); // every 10 days at 16, 17 and 18 $rrule = new RRuleIterator('FREQ=DAILY;BYHOUR=16,17,18;INTERVAL=10', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(4000, 1, 4) ->setTime(16, 0, 0) ->getTimestamp(); @@ -490,13 +488,13 @@ public function testFastForwardBeforeHourlyBasic() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-10-23 00:12:34', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone($timezone)); + $ffDate = new \DateTime('midnight', new \DateTimeZone($timezone)); $ffDate->setDate(4000, 1, 2)->setTime(2, 0, 0); $rrule = new RRuleIterator('FREQ=HOURLY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(4000, 1, 2) ->setTime(1, 12, 34) ->getTimestamp(); @@ -531,21 +529,21 @@ public function testFastForwardBeforeNotInFrequency() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone($timezone)); + $ffDate = new \DateTime('midnight', new \DateTimeZone($timezone)); $ffDate->setDate(2023, 3, 15)->setTime(1, 0, 0); // every leap years $rrule = new RRuleIterator('FREQ=YEARLY;BYMONTH=2;BYMONTHDAY=29', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(2020, 2, 29) ->setTime(0, 0, 0) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // the next leap year - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(2024, 2, 29) ->setTime(0, 0, 0) ->getTimestamp(); @@ -555,10 +553,10 @@ public function testFastForwardBeforeNotInFrequency() public function testFastForwardBeforeMultipleTimesBasic() { - $startDate = new DateTime('2020-01-02 00:00:00', new DateTimeZone('zulu')); - $ffDate = new DateTime('2020-01-18 00:00:00', new DateTimeZone('zulu')); + $startDate = new \DateTime('2020-01-02 00:00:00', new \DateTimeZone('zulu')); + $ffDate = new \DateTime('2020-01-18 00:00:00', new \DateTimeZone('zulu')); $rrule = new RRuleIterator('FREQ=WEEKLY', $startDate); - $expected = new DateTime('2020-01-16 00:00:00', new DateTimeZone('zulu')); + $expected = new \DateTime('2020-01-16 00:00:00', new \DateTimeZone('zulu')); $this->fastForward($rrule, $ffDate); $this->assertEquals($expected->getTimestamp(), $rrule->current()->getTimestamp()); diff --git a/tests/VObject/Recur/FastForwardTest.php b/tests/VObject/Recur/FastForwardTest.php index 7a305b4ad..62effc4de 100644 --- a/tests/VObject/Recur/FastForwardTest.php +++ b/tests/VObject/Recur/FastForwardTest.php @@ -2,13 +2,11 @@ namespace Sabre\VObject\Recur; -use DateTime; -use DateTimeZone; use PHPUnit\Framework\TestCase; class FastForwardTest extends TestCase { - const FF_TIMEOUT = 1000000; // in usec + public const FF_TIMEOUT = 1000000; // in usec private function fastForward(RRuleIterator $ruleIterator, \DateTimeInterface $ffDate) { @@ -22,16 +20,16 @@ private function fastForward(RRuleIterator $ruleIterator, \DateTimeInterface $ff public function testFastForwardYearlyBasic() { - $startDate = new DateTime('1970-10-23 00:00:00', new DateTimeZone('zulu')); - $ffDate = new DateTime('midnight', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(99999, 1, 1); $rrule = new RRuleIterator('FREQ=YEARLY', $startDate); $this->fastForward($rrule, $ffDate); $year = 60 * 60 * 24 * 365; - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(99999, 10, 23) ->setTime(0, 0, 0) ->getTimestamp(); @@ -72,15 +70,15 @@ public function testFastForwardYearlyBasic() public function testFastForwardYearlyByYearDay() { $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(99998, 12, 31); $rrule = new RRuleIterator('FREQ=YEARLY;BYYEARDAY=1,20,300', $startDate); $this->fastForward($rrule, $ffDate); $day = 60 * 60 * 24; - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(99999, 1, 1)// 20th day ->setTime(0, 0, 0) ->getTimestamp(); @@ -116,7 +114,7 @@ public function testFastForwardYearlyByYearDay() public function testFastForwardYearlyByWeekNo() { $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(99999, 1, 1); $rrule = new RRuleIterator('FREQ=YEARLY;BYWEEKNO=1,20', $startDate); @@ -124,8 +122,8 @@ public function testFastForwardYearlyByWeekNo() $day = 60 * 60 * 24; $week = 7 * $day; - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(99999, 1, 4)// 1st day ->setTime(0, 0, 0) ->getTimestamp(); @@ -138,13 +136,13 @@ public function testFastForwardYearlyByWeekNo() public function testFastForwardYearlyAdvanced() { $startDate = new \DateTime('1970-10-23 12:34:56', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(9999, 1, 20)->setTime(0, 0, 13); $rrule = new RRuleIterator('FREQ=YEARLY;INTERVAL=2;BYMONTH=1;BYDAY=SU;BYHOUR=8,9;BYMINUTE=30', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(10000, 1, 2) ->setTime(8, 30, 56) ->getTimestamp(); @@ -188,7 +186,7 @@ public function testFastForwardYearlyAdvanced() // jump to 6th january 10002 $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(10002, 1, 6) ->setTime(8, 30, 56) ->getTimestamp(); @@ -202,13 +200,13 @@ public function testFastForwardYearlyAdvanced() public function testFastForwardMonthlyBasic() { $startDate = new \DateTime('1970-10-23 22:42:31', new \DateTimeZone('zulu')); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(18000, 1, 1); $rrule = new RRuleIterator('FREQ=MONTHLY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(18000, 1, 23) ->setTime(22, 42, 31) ->getTimestamp(); @@ -248,20 +246,20 @@ public function testFastForwardMonthly31thDay() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(18000, 1, 1); $rrule = new RRuleIterator('FREQ=MONTHLY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 1, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // march $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 3, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -269,35 +267,35 @@ public function testFastForwardMonthly31thDay() // may $rrule->next(); $expected += (30 + 31) * 24 * 60 * 60; - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 5, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // july $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 7, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // august $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 8, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // october $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 10, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // december $rrule->next(); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(18000, 12, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -306,63 +304,63 @@ public function testFastForwardMonthly31thDay() public function testFastForwardMonthlyAdvanced() { $timezone = 'America/New_York'; - $startDate = new \DateTime('1970-01-31 00:00:00', new DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone($timezone)); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(8000, 1, 1); $rrule = new RRuleIterator('FREQ=MONTHLY;INTERVAL=2;BYDAY=1MO,2TU,3WE,4TH', $startDate); $this->fastForward($rrule, $ffDate); // monday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 1, 3) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // tuesday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 1, 11) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // wednesday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 1, 19) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // thursday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 1, 27) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // monday march - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 3, 6) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // tuesday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 3, 14) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // wednesday (this month starts on wednesday so that's just the next day) - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 3, 15) ->getTimestamp(); $rrule->next(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); // thursday - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(8000, 3, 23) ->getTimestamp(); $rrule->next(); @@ -373,13 +371,13 @@ public function testFastForwardDailyBasic() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(4000, 1, 1); $rrule = new RRuleIterator('FREQ=DAILY', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(4000, 1, 1) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -413,13 +411,13 @@ public function testFastForwardDailyAdvanced() { $timezone = 'America/New_York'; $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone($timezone)); - $ffDate = new \DateTime('midnight', new DateTimeZone('zulu')); + $ffDate = new \DateTime('midnight', new \DateTimeZone('zulu')); $ffDate->setDate(4000, 1, 1); $rrule = new RRuleIterator('FREQ=DAILY;BYHOUR=16,17,18;INTERVAL=10', $startDate); $this->fastForward($rrule, $ffDate); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(4000, 1, 4) ->setTime(16, 0, 0) ->getTimestamp(); diff --git a/tests/VObject/Recur/FastForwardToEndTest.php b/tests/VObject/Recur/FastForwardToEndTest.php index 992f2b9d8..1073a95df 100644 --- a/tests/VObject/Recur/FastForwardToEndTest.php +++ b/tests/VObject/Recur/FastForwardToEndTest.php @@ -2,15 +2,13 @@ namespace Sabre\VObject\Recur; -use DateTime; -use DateTimeZone; use PHPUnit\Framework\TestCase; class FastForwardToEndTest extends TestCase { - const FF_TIMEOUT = 1000000; // in usec + public const FF_TIMEOUT = 1000000; // in usec - private function fastForwardToEnd(RRuleIterator $ruleIterator, $enfoceTiming = true) + private function fastForwardToEnd(RRuleIterator $ruleIterator, $enfoceTiming = true): void { $ru = getrusage(); $startTime = $ru['ru_utime.tv_sec'] * 1000000 + $ru['ru_utime.tv_usec']; @@ -22,47 +20,47 @@ private function fastForwardToEnd(RRuleIterator $ruleIterator, $enfoceTiming = t $this->assertNotNull($ruleIterator->current()); } - public function testFastForwardToEndWithoutEndYearlyBasic() + public function testFastForwardToEndWithoutEndYearlyBasic(): void { - $startDate = new DateTime('1970-10-23 00:00:00', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); $rrule = new RRuleIterator('FREQ=YEARLY', $startDate); $this->expectException(\LogicException::class); $rrule->fastForwardToEnd(); } - public function testFastForwardToEndCountYearlyBasic() + public function testFastForwardToEndCountYearlyBasic(): void { - $startDate = new DateTime('1970-10-23 00:00:00', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); $rrule = new RRuleIterator('FREQ=YEARLY;COUNT=7777', $startDate); // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(9746, 10, 23) ->setTime(0, 0, 0) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); } - public function testFastForwardToEndUntilYearlyBasic() + public function testFastForwardToEndUntilYearlyBasic(): void { - $startDate = new DateTime('1970-10-23 00:00:00', new DateTimeZone('zulu')); + $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); $rrule = new RRuleIterator('FREQ=YEARLY;UNTIL=97461212T000000', $startDate); $this->fastForwardToEnd($rrule); - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(9746, 10, 23) ->setTime(0, 0, 0) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); } - public function testFastForwardToEndCountYearlyByYearDay() + public function testFastForwardToEndCountYearlyByYearDay(): void { $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); $rrule = new RRuleIterator('FREQ=YEARLY;BYYEARDAY=1,20,300;COUNT=10000', $startDate); @@ -70,23 +68,23 @@ public function testFastForwardToEndCountYearlyByYearDay() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(5303, 1, 20) ->setTime(0, 0, 0) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); } - public function testFastForwardToEndUntilYearlyByYearDay() + public function testFastForwardToEndUntilYearlyByYearDay(): void { $startDate = new \DateTime('1970-10-23 00:00:00', new \DateTimeZone('zulu')); $rrule = new RRuleIterator('FREQ=YEARLY;BYYEARDAY=1,20,300;UNTIL=53030808T000000', $startDate); $this->fastForwardToEnd($rrule); - $expected = (new DateTime()) - ->setTimezone(new DateTimeZone('zulu')) + $expected = (new \DateTime()) + ->setTimezone(new \DateTimeZone('zulu')) ->setDate(5303, 1, 20) ->setTime(0, 0, 0) ->getTimestamp(); @@ -135,7 +133,7 @@ public function testFastForwardToEndCountYearlyAdvanced() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(4226, 1, 1) ->setTime(8, 30, 56) ->getTimestamp(); @@ -149,7 +147,7 @@ public function testFastForwardToEndUntilYearlyAdvanced() $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(4218, 1, 25) ->setTime(8, 30, 56) ->getTimestamp(); @@ -164,7 +162,7 @@ public function testFastForwardToEndCountMonthlyBasic() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(2804, 1, 23) ->setTime(22, 42, 31) ->getTimestamp(); @@ -178,7 +176,7 @@ public function testFastForwardToEndUntilMonthlyBasic() $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone('zulu'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('zulu'))) ->setDate(2803, 12, 23) ->setTime(22, 42, 31) ->getTimestamp(); @@ -196,7 +194,7 @@ public function testFastForwardToEndCountMonthly31thDay() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(3398, 10, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -213,7 +211,7 @@ public function testFastForwardToEndCountMonthly31thDayPHP81() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(3398, 7, 31); $this->assertEquals($expected->getTimestamp(), $rrule->current()->getTimestamp()); } @@ -225,7 +223,7 @@ public function testFastForwardToEndUntilMonthly31thDay() $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(3398, 8, 31) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -233,14 +231,14 @@ public function testFastForwardToEndUntilMonthly31thDay() public function testFastForwardToEndCountMonthlyAdvanced() { - $startDate = new \DateTime('1970-01-31 00:00:00', new DateTimeZone('America/New_York')); + $startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone('America/New_York')); // every 2 months on the 1st Monday, 2nd Tuesday, 3rd Wednesday and 4th Thursday $rrule = new RRuleIterator('FREQ=MONTHLY;INTERVAL=2;BYDAY=1MO,2TU,3WE,4TH;COUNT=10000', $startDate); // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(2386, 9, 17) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -248,13 +246,13 @@ public function testFastForwardToEndCountMonthlyAdvanced() public function testFastForwardToEndUntilMonthlyAdvanced() { - $startDate = new \DateTime('1970-01-31 00:00:00', new DateTimeZone('America/New_York')); + $startDate = new \DateTime('1970-01-31 00:00:00', new \DateTimeZone('America/New_York')); // every 2 months on the 1st Monday, 2nd Tuesday, 3rd Wednesday and 4th Thursday $rrule = new RRuleIterator('FREQ=MONTHLY;INTERVAL=2;BYDAY=1MO,2TU,3WE,4TH;UNTIL=23860914T092500', $startDate); $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone('America/New_York'))) + $expected = (new \DateTime('midnight', new \DateTimeZone('America/New_York'))) ->setDate(2386, 9, 9) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -269,7 +267,7 @@ public function testFastForwardToEndCountDailyBasic() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(2244, 8, 6) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -283,7 +281,7 @@ public function testFastForwardToEndUntilDailyBasic() $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(2244, 8, 6) ->getTimestamp(); $this->assertEquals($expected, $rrule->current()->getTimestamp()); @@ -299,7 +297,7 @@ public function testFastForwardToEndCountDailyAdvanced() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(2062, 1, 13) ->setTime(18, 0, 0) ->getTimestamp(); @@ -315,7 +313,7 @@ public function testFastForwardToEndUntilDailyAdvanced() $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(2062, 1, 13) ->setTime(18, 0, 0) ->getTimestamp(); @@ -331,7 +329,7 @@ public function testFastForwardToEndCountHourlyBasic() // We do not enforce the timing in case of a count rule as we cannot optimize it $this->fastForwardToEnd($rrule, false); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(1982, 3, 21) ->setTime(2, 12, 34) ->getTimestamp(); @@ -346,7 +344,7 @@ public function testFastForwardToEndUntilHourlyBasic() $this->fastForwardToEnd($rrule); - $expected = (new DateTime('midnight', new DateTimeZone($timezone))) + $expected = (new \DateTime('midnight', new \DateTimeZone($timezone))) ->setDate(1982, 3, 21) ->setTime(2, 12, 34) ->getTimestamp(); diff --git a/tests/VObject/Recur/RDateIteratorTest.php b/tests/VObject/Recur/RDateIteratorTest.php index 453d8cf73..5dfe57381 100644 --- a/tests/VObject/Recur/RDateIteratorTest.php +++ b/tests/VObject/Recur/RDateIteratorTest.php @@ -2,56 +2,54 @@ namespace Sabre\VObject\Recur; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; class RDateIteratorTest extends TestCase { - public function testSimple() + public function testSimple(): void { - $utc = new DateTimeZone('UTC'); - $it = new RDateIterator('20140901T000000Z,20141001T000000Z', new DateTimeImmutable('2014-08-01 00:00:00', $utc)); + $utc = new \DateTimeZone('UTC'); + $it = new RDateIterator('20140901T000000Z,20141001T000000Z', new \DateTimeImmutable('2014-08-01 00:00:00', $utc)); $expected = [ - new DateTimeImmutable('2014-08-01 00:00:00', $utc), - new DateTimeImmutable('2014-09-01 00:00:00', $utc), - new DateTimeImmutable('2014-10-01 00:00:00', $utc), + new \DateTimeImmutable('2014-08-01 00:00:00', $utc), + new \DateTimeImmutable('2014-09-01 00:00:00', $utc), + new \DateTimeImmutable('2014-10-01 00:00:00', $utc), ]; - $this->assertEquals( + self::assertEquals( $expected, iterator_to_array($it) ); - $this->assertFalse($it->isInfinite()); + self::assertFalse($it->isInfinite()); } - public function testTimezone() + public function testTimezone(): void { - $tz = new DateTimeZone('Europe/Berlin'); - $it = new RDateIterator('20140901T000000,20141001T000000', new DateTimeImmutable('2014-08-01 00:00:00', $tz)); + $tz = new \DateTimeZone('Europe/Berlin'); + $it = new RDateIterator('20140901T000000,20141001T000000', new \DateTimeImmutable('2014-08-01 00:00:00', $tz)); $expected = [ - new DateTimeImmutable('2014-08-01 00:00:00', $tz), - new DateTimeImmutable('2014-09-01 00:00:00', $tz), - new DateTimeImmutable('2014-10-01 00:00:00', $tz), + new \DateTimeImmutable('2014-08-01 00:00:00', $tz), + new \DateTimeImmutable('2014-09-01 00:00:00', $tz), + new \DateTimeImmutable('2014-10-01 00:00:00', $tz), ]; - $this->assertEquals( + self::assertEquals( $expected, iterator_to_array($it) ); - $this->assertFalse($it->isInfinite()); + self::assertFalse($it->isInfinite()); } - public function testFastForward() + public function testFastForward(): void { - $utc = new DateTimeZone('UTC'); - $it = new RDateIterator('20140901T000000Z,20141001T000000Z', new DateTimeImmutable('2014-08-01 00:00:00', $utc)); + $utc = new \DateTimeZone('UTC'); + $it = new RDateIterator('20140901T000000Z,20141001T000000Z', new \DateTimeImmutable('2014-08-01 00:00:00', $utc)); - $it->fastForward(new DateTimeImmutable('2014-08-15 00:00:00')); + $it->fastForward(new \DateTimeImmutable('2014-08-15 00:00:00')); $result = []; while ($it->valid()) { @@ -60,15 +58,15 @@ public function testFastForward() } $expected = [ - new DateTimeImmutable('2014-09-01 00:00:00', $utc), - new DateTimeImmutable('2014-10-01 00:00:00', $utc), + new \DateTimeImmutable('2014-09-01 00:00:00', $utc), + new \DateTimeImmutable('2014-10-01 00:00:00', $utc), ]; - $this->assertEquals( + self::assertEquals( $expected, $result ); - $this->assertFalse($it->isInfinite()); + self::assertFalse($it->isInfinite()); } } diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php index 6cb3feb5b..3384506f5 100644 --- a/tests/VObject/Recur/RRuleIteratorTest.php +++ b/tests/VObject/Recur/RRuleIteratorTest.php @@ -2,15 +2,12 @@ namespace Sabre\VObject\Recur; -use DateTime; -use DateTimeImmutable; -use DateTimeZone; use PHPUnit\Framework\TestCase; use Sabre\VObject\InvalidDataException; class RRuleIteratorTest extends TestCase { - public function testHourly() + public function testHourly(): void { $this->parse( 'FREQ=HOURLY;INTERVAL=3;COUNT=12', @@ -33,7 +30,7 @@ public function testHourly() ); } - public function testDaily() + public function testDaily(): void { $this->parse( 'FREQ=DAILY;INTERVAL=3;UNTIL=20111025T000000Z', @@ -47,11 +44,11 @@ public function testDaily() '2011-10-22 00:00:00', '2011-10-25 00:00:00', ], - 'daily', null, 3, new DateTime('2011-10-25') + 'daily', null, 3, new \DateTime('2011-10-25') ); } - public function testDailyByDayByHour() + public function testDailyByDayByHour(): void { $this->parse( 'FREQ=DAILY;BYDAY=SA,SU;BYHOUR=6,7', @@ -74,7 +71,7 @@ public function testDailyByDayByHour() ); } - public function testDailyByHour() + public function testDailyByHour(): void { $this->parse( 'FREQ=DAILY;INTERVAL=2;BYHOUR=10,11,12,13,14,15', @@ -97,7 +94,7 @@ public function testDailyByHour() ); } - public function testDailyByDay() + public function testDailyByDay(): void { $this->parse( 'FREQ=DAILY;INTERVAL=2;BYDAY=TU,WE,FR', @@ -120,7 +117,7 @@ public function testDailyByDay() ); } - public function testDailyCount() + public function testDailyCount(): void { $this->parse( 'FREQ=DAILY;COUNT=5', @@ -136,7 +133,7 @@ public function testDailyCount() ); } - public function testDailyByMonth() + public function testDailyByMonth(): void { $this->parse( 'FREQ=DAILY;BYMONTH=9,10;BYDAY=SU', @@ -154,7 +151,24 @@ public function testDailyByMonth() ); } - public function testWeekly() + /** + * This test can take some seconds to complete. + * The "large" annotation means phpunit will let it run for + * up to 60 seconds by default. + * + * @large + */ + public function testDailyBySetPosLoop(): void + { + $this->parse( + 'FREQ=DAILY;INTERVAL=7;BYDAY=MO', + '2022-03-15', + [], + 'daily', null, 7, null, '2022-05-01' + ); + } + + public function testWeekly(): void { $this->parse( 'FREQ=WEEKLY;INTERVAL=2;COUNT=10', @@ -175,7 +189,7 @@ public function testWeekly() ); } - public function testWeeklyByDay() + public function testWeeklyByDay(): void { $this->parse( 'FREQ=WEEKLY;INTERVAL=1;COUNT=4;BYDAY=MO;WKST=SA', @@ -190,7 +204,7 @@ public function testWeeklyByDay() ); } - public function testWeeklyByDay2() + public function testWeeklyByDay2(): void { $this->parse( 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU', @@ -213,7 +227,7 @@ public function testWeeklyByDay2() ); } - public function testWeeklyByDayByHour() + public function testWeeklyByDayByHour(): void { $this->parse( 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=MO;BYHOUR=8,9,10', @@ -239,7 +253,7 @@ public function testWeeklyByDayByHour() ); } - public function testWeeklyByDaySpecificHour() + public function testWeeklyByDaySpecificHour(): void { $this->parse( 'FREQ=WEEKLY;INTERVAL=2;BYDAY=TU,WE,FR;WKST=SU', @@ -262,7 +276,7 @@ public function testWeeklyByDaySpecificHour() ); } - public function testMonthly() + public function testMonthly(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=3;COUNT=5', @@ -278,7 +292,7 @@ public function testMonthly() ); } - public function testMonthlyEndOfMonth() + public function testMonthlyEndOfMonth(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=2;COUNT=12', @@ -301,7 +315,7 @@ public function testMonthlyEndOfMonth() ); } - public function testMonthlyByMonthDay() + public function testMonthlyByMonthDay(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=5;COUNT=9;BYMONTHDAY=1,31,-7', @@ -321,7 +335,7 @@ public function testMonthlyByMonthDay() ); } - public function testInvalidByMonthDay() + public function testInvalidByMonthDay(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -332,7 +346,7 @@ public function testInvalidByMonthDay() } /** @dataProvider invalidFreqByCombinationProviders */ - public function testInvalidFreqByCombination(string $rule) + public function testInvalidFreqByCombination(string $rule): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -355,7 +369,7 @@ public function invalidFreqByCombinationProviders(): iterable ]; } - public function testMonthlyByDay() + public function testMonthlyByDay(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=2;COUNT=16;BYDAY=MO,-2TU,+1WE,3TH', @@ -382,7 +396,7 @@ public function testMonthlyByDay() ); } - public function testMonthlyByDayUntil() + public function testMonthlyByDayUntil(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=1;BYDAY=WE;WKST=WE;UNTIL=20210317T000000Z', @@ -395,11 +409,11 @@ public function testMonthlyByDayUntil() '2021-03-10 00:00:00', '2021-03-17 00:00:00', ], - 'monthly', null, 1, new DateTime('2021-03-17') + 'monthly', null, 1, new \DateTime('2021-03-17') ); } - public function testMonthlyByDayUntilWithImpossibleNextOccurrence() + public function testMonthlyByDayUntilWithImpossibleNextOccurrence(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=1;BYDAY=2WE;BYMONTHDAY=2;WKST=WE;UNTIL=20210317T000000Z', @@ -407,11 +421,11 @@ public function testMonthlyByDayUntilWithImpossibleNextOccurrence() [ '2021-02-10 00:00:00', ], - 'monthly', null, 1, new DateTime('2021-03-17') + 'monthly', null, 1, new \DateTime('2021-03-17') ); } - public function testMonthlyByDayByMonthDay() + public function testMonthlyByDayByMonthDay(): void { $this->parse( 'FREQ=MONTHLY;COUNT=10;BYDAY=MO;BYMONTHDAY=1', @@ -432,7 +446,7 @@ public function testMonthlyByDayByMonthDay() ); } - public function testMonthlyByDayBySetPos() + public function testMonthlyByDayBySetPos(): void { $this->parse( 'FREQ=MONTHLY;COUNT=10;BYDAY=MO,TU,WE,TH,FR;BYSETPOS=1,-1', @@ -453,7 +467,7 @@ public function testMonthlyByDayBySetPos() ); } - public function testYearly() + public function testYearly(): void { $this->parse( 'FREQ=YEARLY;COUNT=10;INTERVAL=3', @@ -474,7 +488,7 @@ public function testYearly() ); } - public function testYearlyLeapYear() + public function testYearlyLeapYear(): void { $this->parse( 'FREQ=YEARLY;COUNT=3', @@ -488,7 +502,7 @@ public function testYearlyLeapYear() ); } - public function testYearlyByMonth() + public function testYearlyByMonth(): void { $this->parse( 'FREQ=YEARLY;COUNT=8;INTERVAL=4;BYMONTH=4,10', @@ -507,7 +521,7 @@ public function testYearlyByMonth() ); } - public function testYearlyByMonthInvalidValue1() + public function testYearlyByMonthInvalidValue1(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -517,7 +531,7 @@ public function testYearlyByMonthInvalidValue1() ); } - public function testYearlyByMonthInvalidValue2() + public function testYearlyByMonthInvalidValue2(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -527,7 +541,7 @@ public function testYearlyByMonthInvalidValue2() ); } - public function testYearlyByMonthManyInvalidValues() + public function testYearlyByMonthManyInvalidValues(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -537,7 +551,7 @@ public function testYearlyByMonthManyInvalidValues() ); } - public function testYearlyByMonthEmptyValue() + public function testYearlyByMonthEmptyValue(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -547,7 +561,7 @@ public function testYearlyByMonthEmptyValue() ); } - public function testYearlyByMonthByDay() + public function testYearlyByMonthByDay(): void { $this->parse( 'FREQ=YEARLY;COUNT=8;INTERVAL=5;BYMONTH=4,10;BYDAY=1MO,-1SU', @@ -584,7 +598,25 @@ public function testYearlyNewYearsEve() ); } - public function testYearlyByYearDay() + public function testYearlyNewYearsDay(): void + { + $this->parse( + 'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=1', + '2011-01-01 03:07:00', + [ + '2011-01-01 03:07:00', + '2013-01-01 03:07:00', + '2015-01-01 03:07:00', + '2017-01-01 03:07:00', + '2019-01-01 03:07:00', + '2021-01-01 03:07:00', + '2023-01-01 03:07:00', + ], + 'yearly', 7, 2 + ); + } + + public function testYearlyByYearDay(): void { $this->parse( 'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=190', @@ -606,22 +638,22 @@ public function testYearlyByYearDay() * Regression test for #383 * $parser->next() used to cause an infinite loop. */ - public function testYearlyByYearDayImmutable() + public function testYearlyByYearDayImmutable(): void { $start = '2011-07-10 03:07:00'; $rule = 'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=190'; $tz = 'UTC'; - $dt = new DateTimeImmutable($start, new DateTimeZone($tz)); + $dt = new \DateTimeImmutable($start, new \DateTimeZone($tz)); $parser = new RRuleIterator($rule, $dt); $parser->next(); $item = $parser->current(); - $this->assertEquals($item->format('Y-m-d H:i:s'), '2013-07-09 03:07:00'); + self::assertEquals('2013-07-09 03:07:00', $item->format('Y-m-d H:i:s')); } - public function testYearlyByYearDayMultiple() + public function testYearlyByYearDayMultiple(): void { $this->parse( 'FREQ=YEARLY;COUNT=8;INTERVAL=3;BYYEARDAY=190,301', @@ -640,7 +672,7 @@ public function testYearlyByYearDayMultiple() ); } - public function testYearlyByYearDayByDay() + public function testYearlyByYearDayByDay(): void { $this->parse( 'FREQ=YEARLY;COUNT=6;BYYEARDAY=97;BYDAY=SA', @@ -657,7 +689,7 @@ public function testYearlyByYearDayByDay() ); } - public function testYearlyByYearDayNegative() + public function testYearlyByYearDayNegative(): void { $this->parse( 'FREQ=YEARLY;COUNT=8;BYYEARDAY=-97,-5', @@ -720,7 +752,56 @@ public function testFirstFourthSundayEveryOtherMonthAt830and930() ); } - public function testYearlyByYearDayInvalid390() + /* + * Verifies that -365 back in the year is usually 1 Jan, but + * in leap years it is 2 Jan. + */ + public function testYearlyByYearDayLargeNegative(): void + { + $this->parse( + 'FREQ=YEARLY;COUNT=8;BYYEARDAY=-365', + '2001-01-01 14:53:11', + [ + '2001-01-01 14:53:11', + '2002-01-01 14:53:11', + '2003-01-01 14:53:11', + '2004-01-02 14:53:11', + '2005-01-01 14:53:11', + '2006-01-01 14:53:11', + '2007-01-01 14:53:11', + '2008-01-02 14:53:11', + ], + 'yearly', 8, 1 + ); + } + + /* + * Verifies that -366 back in the year is 1 Jan in a leap year + * Interestingly, it goes back to 31 Dec of the previous year + * when not a leap year. The spec says that -366 is valid, and + * makes no mention of it being valid only in a leap year, so + * the behavior seems reasonable. + */ + public function testYearlyByYearDayMaxNegative(): void + { + $this->parse( + 'FREQ=YEARLY;COUNT=8;BYYEARDAY=-366', + '2001-01-01 14:53:11', + [ + '2001-01-01 14:53:11', + '2001-12-31 14:53:11', + '2002-12-31 14:53:11', + '2004-01-01 14:53:11', + '2004-12-31 14:53:11', + '2005-12-31 14:53:11', + '2006-12-31 14:53:11', + '2008-01-01 14:53:11', + ], + 'yearly', 8, 1 + ); + } + + public function testYearlyByYearDayInvalid390(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -731,7 +812,7 @@ public function testYearlyByYearDayInvalid390() ); } - public function testYearlyByYearDayInvalid0() + public function testYearlyByYearDayInvalid0(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -742,7 +823,7 @@ public function testYearlyByYearDayInvalid0() ); } - public function testYearlyByDayByWeekNo() + public function testYearlyByDayByWeekNo(): void { $this->parse( 'FREQ=YEARLY;COUNT=3;BYDAY=MO;BYWEEKNO=13,15,50', @@ -756,7 +837,7 @@ public function testYearlyByDayByWeekNo() ); } - public function testFastForward() + public function testFastForward(): void { // The idea is that we're fast-forwarding too far in the future, so // there will be no results left. @@ -779,7 +860,7 @@ public function testFastForward() * * @medium */ - public function testFifthTuesdayProblem() + public function testFifthTuesdayProblem(): void { $this->parse( 'FREQ=MONTHLY;INTERVAL=1;UNTIL=20071030T035959Z;BYDAY=5TU', @@ -787,7 +868,7 @@ public function testFifthTuesdayProblem() [ '2007-10-04 14:46:42', ], - 'monthly', null, 1, new DateTime('2007-10-30 03:59:59') + 'monthly', null, 1, new \DateTime('2007-10-30 03:59:59') ); } @@ -795,7 +876,7 @@ public function testFifthTuesdayProblem() * This bug came from a Fruux customer. This would result in a never-ending * request. */ - public function testFastForwardTooFar() + public function testFastForwardTooFar(): void { $this->parse( 'FREQ=WEEKLY;BYDAY=MO;UNTIL=20090704T205959Z;INTERVAL=1', @@ -813,11 +894,11 @@ public function testFastForwardTooFar() '2009-06-22 18:00:00', '2009-06-29 18:00:00', ], - 'weekly', null, 1, new DateTime('2009-07-04 20:59:59') + 'weekly', null, 1, new \DateTime('2009-07-04 20:59:59') ); } - public function testValidByWeekNo() + public function testValidByWeekNo(): void { $this->parse( 'FREQ=YEARLY;BYWEEKNO=20;BYDAY=TU', @@ -840,7 +921,7 @@ public function testValidByWeekNo() ); } - public function testNegativeValidByWeekNo() + public function testNegativeValidByWeekNo(): void { $this->parse( 'FREQ=YEARLY;BYWEEKNO=-20;BYDAY=TU,FR', @@ -863,7 +944,7 @@ public function testNegativeValidByWeekNo() ); } - public function testTwoValidByWeekNo() + public function testTwoValidByWeekNo(): void { $this->parse( 'FREQ=YEARLY;BYWEEKNO=20;BYDAY=TU,FR', @@ -886,7 +967,7 @@ public function testTwoValidByWeekNo() ); } - public function testValidByWeekNoByDayDefault() + public function testValidByWeekNoByDayDefault(): void { $this->parse( 'FREQ=YEARLY;BYWEEKNO=20', @@ -909,7 +990,7 @@ public function testValidByWeekNoByDayDefault() ); } - public function testMultipleValidByWeekNo() + public function testMultipleValidByWeekNo(): void { $this->parse( 'FREQ=YEARLY;BYWEEKNO=20,50;BYDAY=TU,FR', @@ -932,21 +1013,20 @@ public function testMultipleValidByWeekNo() ); } - public function testInvalidByWeekNo() + public function testInvalidByWeekNo(): void { $this->expectException(InvalidDataException::class); $this->parse( 'FREQ=YEARLY;BYWEEKNO=54', '2011-05-16 00:00:00', - [ - ] + [], ); } /** * This also at one point caused an infinite loop. We're keeping the test. */ - public function testYearlyByMonthLoop() + public function testYearlyByMonthLoop(): void { $this->parse( 'FREQ=YEARLY;INTERVAL=1;UNTIL=20120203T225959Z;BYMONTH=2;BYSETPOS=1;BYDAY=SU,MO,TU,WE,TH,FR,SA', @@ -954,17 +1034,34 @@ public function testYearlyByMonthLoop() [ '2012-02-01 15:45:00', ], - 'yearly', null, 1, new DateTime('2012-02-03 22:59:59'), + 'yearly', null, 1, new \DateTime('2012-02-03 22:59:59'), '2012-01-29 23:00:00' ); } + /** + * This test can take some seconds to complete. + * The "large" annotation means phpunit will let it run for + * up to 60 seconds by default. + * + * @large + */ + public function testYearlyBySetPosLoop(): void + { + $this->parse( + 'FREQ=YEARLY;BYMONTH=5;BYSETPOS=3;BYMONTHDAY=3', + '2022-03-03 15:45:00', + [], + 'yearly', null, 1, null, '2022-05-01' + ); + } + /** * Something, somewhere produced an ics with an interval set to 0. Because * this means we increase the current day (or week, month) by 0, this also * results in an infinite loop. */ - public function testZeroInterval() + public function testZeroInterval(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -976,7 +1073,7 @@ public function testZeroInterval() ); } - public function testInvalidFreq() + public function testInvalidFreq(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -986,7 +1083,7 @@ public function testInvalidFreq() ); } - public function testInvalidMissingFreq() + public function testInvalidMissingFreq(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -996,7 +1093,7 @@ public function testInvalidMissingFreq() ); } - public function testByDayBadOffset() + public function testByDayBadOffset(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -1006,7 +1103,7 @@ public function testByDayBadOffset() ); } - public function testUntilBeginHasTimezone() + public function testUntilBeginHasTimezone(): void { $this->parse( 'FREQ=WEEKLY;UNTIL=20131118T183000', @@ -1022,13 +1119,13 @@ public function testUntilBeginHasTimezone() '2013-11-11 18:30:00', '2013-11-18 18:30:00', ], - 'weekly', null, 1, new DateTime('2013-11-18 18:30:00-0500'), + 'weekly', null, 1, new \DateTime('2013-11-18 18:30:00-0500'), null, 'America/New_York' ); } - public function testUntilBeforeDtStart() + public function testUntilBeforeDtStart(): void { $dtstart = '2014-08-02 00:15:00'; $this->parse( @@ -1037,7 +1134,7 @@ public function testUntilBeforeDtStart() [ $dtstart, ], - 'daily', null, 1, new DateTime($dtstart) + 'daily', null, 1, new \DateTime($dtstart) ); } @@ -1053,7 +1150,7 @@ public function testUntilAndCount() ); } - public function testIgnoredStuff() + public function testIgnoredStuff(): void { $this->parse( 'FREQ=DAILY;BYSECOND=1;BYMINUTE=1;COUNT=2', @@ -1066,7 +1163,7 @@ public function testIgnoredStuff() ); } - public function testMinusFifthThursday() + public function testMinusFifthThursday(): void { $this->parse( 'FREQ=MONTHLY;BYDAY=-4TH,-5TH;COUNT=4', @@ -1088,7 +1185,7 @@ public function testMinusFifthThursday() * * @large */ - public function testNeverEnding() + public function testNeverEnding(): void { $this->parse( 'FREQ=MONTHLY;BYDAY=2TU;BYSETPOS=2', @@ -1103,7 +1200,7 @@ public function testNeverEnding() ); } - public function testUnsupportedPart() + public function testUnsupportedPart(): void { $this->expectException(InvalidDataException::class); $this->parse( @@ -1113,26 +1210,26 @@ public function testUnsupportedPart() ); } - public function testIteratorFunctions() + public function testIteratorFunctions(): void { - $parser = new RRuleIterator('FREQ=DAILY', new DateTime('2014-08-02 00:00:13')); + $parser = new RRuleIterator('FREQ=DAILY', new \DateTime('2014-08-02 00:00:13')); $parser->next(); - $this->assertEquals( - new DateTime('2014-08-03 00:00:13'), + self::assertEquals( + new \DateTime('2014-08-03 00:00:13'), $parser->current() ); - $this->assertEquals( + self::assertEquals( 1, $parser->key() ); $parser->rewind(); - $this->assertEquals( - new DateTime('2014-08-02 00:00:13'), + self::assertEquals( + new \DateTime('2014-08-02 00:00:13'), $parser->current() ); - $this->assertEquals( + self::assertEquals( 0, $parser->key() ); @@ -1140,17 +1237,17 @@ public function testIteratorFunctions() public function parse( $rule, - $start, - $expected, + string $start, + array $expected, $expectedFreq = null, $expectedCount = null, $expectedInterval = null, $expectedUntil = null, - $fastForward = null, - $tz = 'UTC', - $runTillTheEnd = false - ) { - $dt = new DateTime($start, new DateTimeZone($tz)); + string $fastForward = null, + string $tz = 'UTC', + bool $runTillTheEnd = false + ): void { + $dt = new \DateTime($start, new \DateTimeZone($tz)); $parser = new RRuleIterator($rule, $dt); $this->assertEquals($expectedFreq, $parser->getFrequency()); @@ -1159,7 +1256,7 @@ public function parse( $this->assertEquals($expectedUntil, $parser->getUntil()); if ($fastForward) { - $parser->fastForward(new DateTime($fastForward)); + $parser->fastForward(new \DateTime($fastForward)); } $result = []; @@ -1173,7 +1270,7 @@ public function parse( $parser->next(); } - $this->assertEquals( + self::assertEquals( $expected, $result ); diff --git a/tests/VObject/SlashRTest.php b/tests/VObject/SlashRTest.php index 688563af1..8f968d3c9 100644 --- a/tests/VObject/SlashRTest.php +++ b/tests/VObject/SlashRTest.php @@ -10,10 +10,10 @@ */ class SlashRTest extends TestCase { - public function testEncode() + public function testEncode(): void { $vcal = new Component\VCalendar(); $prop = $vcal->add('test', "abc\r\ndef"); - $this->assertEquals("TEST:abc\\ndef\r\n", $prop->serialize()); + self::assertEquals("TEST:abc\\ndef\r\n", $prop->serialize()); } } diff --git a/tests/VObject/Splitter/ICalendarTest.php b/tests/VObject/Splitter/ICalendarTest.php index 2788b96d6..f5428e937 100644 --- a/tests/VObject/Splitter/ICalendarTest.php +++ b/tests/VObject/Splitter/ICalendarTest.php @@ -8,14 +8,14 @@ class ICalendarTest extends TestCase { - protected $version; + protected string $version; public function setUp(): void { $this->version = VObject\Version::VERSION; } - public function createStream($data) + public function createStream(string $data) { $stream = fopen('php://memory', 'r+'); fwrite($stream, $data); @@ -24,7 +24,7 @@ public function createStream($data) return $stream; } - public function testICalendarImportValidEvent() + public function testICalendarImportValidEvent(): void { $data = <<getNext()) { $return .= $object->serialize(); } - $this->assertEquals([], VObject\Reader::read($return)->validate()); + self::assertEquals([], VObject\Reader::read($return)->validate()); } - public function testICalendarImportWrongType() + public function testICalendarImportWrongType(): void { $this->expectException(ParseException::class); $data = <<createStream($data); - $objects = new ICalendar($tempFile); + new ICalendar($tempFile); } - public function testICalendarImportEndOfData() + public function testICalendarImportEndOfData(): void { $data = <<getNext()) { $return .= $object->serialize(); } - $this->assertNull($object = $objects->getNext()); + self::assertNull($objects->getNext()); } - public function testICalendarImportInvalidEvent() + public function testICalendarImportInvalidEvent(): void { $this->expectException(ParseException::class); $data = <<createStream($data); - $objects = new ICalendar($tempFile); + new ICalendar($tempFile); } - public function testICalendarImportMultipleValidEvents() + public function testICalendarImportMultipleValidEvents(): void { $event[] = <<serialize(); $expected = str_replace("\n", "\r\n", $expected); - $this->assertEquals($expected, $object->serialize()); + self::assertEquals($expected, $object->serialize()); ++$i; } - $this->assertEquals([], VObject\Reader::read($return)->validate()); + self::assertEquals([], VObject\Reader::read($return)->validate()); } - public function testICalendarImportEventWithoutUID() + public function testICalendarImportEventWithoutUID(): void { $data = <<fail('Validation errors: '.implode("\n", $messages)); } else { - $this->assertEquals([], $messages); + self::assertEquals([], $messages); } } - public function testICalendarImportMultipleVTIMEZONESAndMultipleValidEvents() + public function testICalendarImportMultipleVTIMEZONESAndMultipleValidEvents(): void { $timezones = <<assertEquals($expected, $object->serialize()); + self::assertEquals($expected, $object->serialize()); $return .= $object->serialize(); ++$i; } - $this->assertEquals([], VObject\Reader::read($return)->validate()); + self::assertEquals([], VObject\Reader::read($return)->validate()); } - public function testICalendarImportWithOutVTIMEZONES() + public function testICalendarImportWithOutVTIMEZONES(): void { $data = <<validate(); - $this->assertEquals([], $messages); + self::assertEquals([], $messages); } } diff --git a/tests/VObject/Splitter/VCardTest.php b/tests/VObject/Splitter/VCardTest.php index 1402b5094..7ebb07b95 100644 --- a/tests/VObject/Splitter/VCardTest.php +++ b/tests/VObject/Splitter/VCardTest.php @@ -16,7 +16,7 @@ public function createStream($data) return $stream; } - public function testVCardImportValidVCard() + public function testVCardImportValidVCard(): void { $data = <<getNext()) { ++$count; } - $this->assertEquals(1, $count); + self::assertEquals(1, $count); } - public function testVCardImportWrongType() + public function testVCardImportWrongType(): void { $this->expectException(ParseException::class); $event[] = <<getNext()) { + while ($splitter->getNext()) { } } - public function testVCardImportValidVCardsWithCategories() + public function testVCardImportValidVCardsWithCategories(): void { $data = <<getNext()) { + while ($splitter->getNext()) { ++$count; } - $this->assertEquals(4, $count); + self::assertEquals(4, $count); } - public function testVCardImportVCardNoComponent() + public function testVCardImportVCardNoComponent(): void { $this->expectException(ParseException::class); $data = <<expectException(ParseException::class); $this->expectExceptionMessage('Invalid MimeDir file. Unexpected component: "BEGIN:VCARD" in document type VCARD'); - while ($object = $splitter->getNext()) { + while ($splitter->getNext()) { } } - public function testVCardImportQuotedPrintableOptionForgivingLeading() + public function testVCardImportQuotedPrintableOptionForgivingLeading(): void { $data = <<getNext()) { + while ($splitter->getNext()) { ++$count; } - $this->assertEquals(2, $count); + self::assertEquals(2, $count); } - public function testVCardImportEndOfData() + public function testVCardImportEndOfData(): void { $data = <<createStream($data); $objects = new VCard($tempFile); - $object = $objects->getNext(); + $objects->getNext(); - $this->assertNull($objects->getNext()); + self::assertNull($objects->getNext()); } - public function testVCardImportCheckInvalidArgumentException() + public function testVCardImportCheckInvalidArgumentException(): void { $this->expectException(ParseException::class); $data = <<getNext()) { ++$count; } - $this->assertEquals(2, $count); + self::assertEquals(2, $count); } - public function testImportMultipleSeparatedWithNewLines() + public function testImportMultipleSeparatedWithNewLines(): void { $data = <<getNext()) { ++$count; } - $this->assertEquals(2, $count); + self::assertEquals(2, $count); } - public function testVCardImportVCardWithoutUID() + public function testVCardImportVCardWithoutUID(): void { $data = <<assertEquals(1, $count); + self::assertEquals(1, $count); } } diff --git a/tests/VObject/StringUtilTest.php b/tests/VObject/StringUtilTest.php index c614f6aac..6d6b9b05e 100644 --- a/tests/VObject/StringUtilTest.php +++ b/tests/VObject/StringUtilTest.php @@ -6,45 +6,46 @@ class StringUtilTest extends TestCase { - public function testNonUTF8() + public function testNonUTF8(): void { - $string = StringUtil::isUTF8(chr(0xbf)); + $string = StringUtil::isUTF8(chr(0xBF)); - $this->assertEquals(false, $string); + self::assertEquals(false, $string); } - public function testIsUTF8() + public function testIsUTF8(): void { $string = StringUtil::isUTF8('I 💚 SabreDAV'); - $this->assertEquals(true, $string); + self::assertEquals(true, $string); } - public function testUTF8ControlChar() + public function testUTF8ControlChar(): void { $string = StringUtil::isUTF8(chr(0x00)); - $this->assertEquals(false, $string); + self::assertEquals(false, $string); } - public function testConvertToUTF8nonUTF8() + public function testConvertToUTF8nonUTF8(): void { - $string = StringUtil::convertToUTF8(chr(0xbf)); + // 0xBF is an ASCII upside-down question mark + $string = StringUtil::convertToUTF8(chr(0xBF)); - $this->assertEquals(utf8_encode(chr(0xbf)), $string); + self::assertEquals(mb_convert_encoding(chr(0xBF), 'UTF-8', 'ISO-8859-1'), $string); } - public function testConvertToUTF8IsUTF8() + public function testConvertToUTF8IsUTF8(): void { $string = StringUtil::convertToUTF8('I 💚 SabreDAV'); - $this->assertEquals('I 💚 SabreDAV', $string); + self::assertEquals('I 💚 SabreDAV', $string); } - public function testConvertToUTF8ControlChar() + public function testConvertToUTF8ControlChar(): void { $string = StringUtil::convertToUTF8(chr(0x00)); - $this->assertEquals('', $string); + self::assertEquals('', $string); } } diff --git a/tests/VObject/TimeZoneUtilTest.php b/tests/VObject/TimeZoneUtilTest.php index ff409a1ff..1069b437a 100644 --- a/tests/VObject/TimeZoneUtilTest.php +++ b/tests/VObject/TimeZoneUtilTest.php @@ -14,11 +14,11 @@ public function setUp(): void /** * @dataProvider getMapping */ - public function testCorrectTZ($timezoneName) + public function testCorrectTZ(string $timezoneName): void { try { $tz = new \DateTimeZone($timezoneName); - $this->assertInstanceOf('DateTimeZone', $tz); + self::assertInstanceOf('DateTimeZone', $tz); } catch (\Exception $e) { if (false !== strpos($e->getMessage(), 'Unknown or bad timezone')) { $this->markTestSkipped($timezoneName.' is not (yet) supported in this PHP version. Update pecl/timezonedb'); @@ -28,14 +28,14 @@ public function testCorrectTZ($timezoneName) } } - public function getMapping() + public function getMapping(): array { $map = array_merge( include __DIR__.'/../../lib/timezonedata/windowszones.php', include __DIR__.'/../../lib/timezonedata/lotuszones.php', include __DIR__.'/../../lib/timezonedata/exchangezones.php', include __DIR__.'/../../lib/timezonedata/php-workaround.php', - include __DIR__.'/../../lib/timezonedata/extrazones.php' + include __DIR__.'/../../lib/timezonedata/extrazones.php', ); // PHPUNit requires an array of arrays @@ -50,15 +50,15 @@ function ($value) { /** * @dataProvider getMapping */ - public function testSlashTZ($timezonename) + public function testSlashTZ($timezonename): void { $slashTimezone = '/'.$timezonename; $expected = TimeZoneUtil::getTimeZone($timezonename)->getName(); $actual = TimeZoneUtil::getTimeZone($slashTimezone)->getName(); - $this->assertEquals($expected, $actual); + self::assertEquals($expected, $actual); } - public function testExchangeMap() + public function testExchangeMap(): void { $vobj = <<assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testWhetherMicrosoftIsStillInsane() + public function testWhetherMicrosoftIsStillInsane(): void { $vobj = <<assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testUnknownExchangeId() + public function testUnknownExchangeId(): void { $vobj = <<assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testEmptyTimeZone() + public function testEmptyTimeZone(): void { $tz = TimeZoneUtil::getTimeZone(''); $ex = new \DateTimeZone('UTC'); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testWindowsTimeZone() + public function testWindowsTimeZone(): void { $tz = TimeZoneUtil::getTimeZone('Eastern Standard Time'); $ex = new \DateTimeZone('America/New_York'); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testLowerCaseTimeZone() + public function testLowerCaseTimeZone(): void { $tz = TimeZoneUtil::getTimeZone('mountain time (us & canada)'); $ex = new \DateTimeZone('America/Denver'); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testDeprecatedTimeZone() + public function testDeprecatedTimeZone(): void { // Deprecated in 2022b $tz = TimeZoneUtil::getTimeZone('Europe/Kiev'); $ex = new \DateTimeZone('Europe/Kiev'); - $this->assertSame($ex->getName(), $tz->getName()); + self::assertSame($ex->getName(), $tz->getName()); } - public function testDeprecatedUnsupportedTimeZone() + public function testDeprecatedUnsupportedTimeZone(): void { // Deprecated and unsupported $tz = TimeZoneUtil::getTimeZone('America/Godthab'); $ex = new \DateTimeZone('America/Godthab'); - $this->assertNotSame($ex->getName(), $tz->getName()); + self::assertNotSame($ex->getName(), $tz->getName()); } /** * @dataProvider getPHPTimeZoneIdentifiers */ - public function testTimeZoneIdentifiers($tzid) + public function testTimeZoneIdentifiers(string $tzid): void { $tz = TimeZoneUtil::getTimeZone($tzid); $ex = new \DateTimeZone($tzid); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } /** * @dataProvider getPHPTimeZoneBCIdentifiers */ - public function testTimeZoneBCIdentifiers($tzid) - { + public function testTimeZoneBCIdentifiers(string $tzid): void + { + /* + * A regression was introduced in PHP 8.1.14 and 8.2.1 + * Timezone ids containing a "+" like "GMT+10" do not work. + * See https://github.com/php/php-src/issues/10218 + * The regression should be fixed in the next patch releases of PHP + * that should be released in Feb 2023. + */ + $versionOfPHP = \phpversion(); + if ((('8.1.14' == $versionOfPHP) || ('8.2.1' == $versionOfPHP)) && \str_contains($tzid, '+')) { + $this->markTestSkipped("Timezone ids containing '+' do not work on PHP $versionOfPHP"); + } $tz = TimeZoneUtil::getTimeZone($tzid); $ex = new \DateTimeZone($tzid); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function getPHPTimeZoneIdentifiers() + public function getPHPTimeZoneIdentifiers(): array { // PHPUNit requires an array of arrays return array_map( @@ -231,12 +242,12 @@ function ($value) { }, // FIXME remove the filter after finishing timezone migration array_filter(\DateTimeZone::listIdentifiers(), static function (string $timezone) { - return $timezone !== 'Europe/Kyiv'; + return 'Europe/Kyiv' !== $timezone; }) ); } - public function getPHPTimeZoneBCIdentifiers() + public function getPHPTimeZoneBCIdentifiers(): array { // PHPUNit requires an array of arrays return array_map( @@ -247,13 +258,12 @@ function ($value) { ); } - public function testKyivTimezone() + public function testKyivTimezone(): void { - - $this->assertSame('Europe/Kiev', TimeZoneUtil::getTimeZone('Europe/Kyiv')->getName()); + self::assertSame('Europe/Kiev', TimeZoneUtil::getTimeZone('Europe/Kyiv')->getName()); } - public function testTimezoneOffset() + public function testTimezoneOffset(): void { $tz = TimeZoneUtil::getTimeZone('GMT-0400', null, true); @@ -262,16 +272,16 @@ public function testTimezoneOffset() } else { $ex = new \DateTimeZone('Etc/GMT-4'); } - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testTimezoneFail() + public function testTimezoneFail(): void { - $this->expectException(\InvalidArgumentException::class); - $tz = TimeZoneUtil::getTimeZone('FooBar', null, true); + self::expectException(\InvalidArgumentException::class); + TimeZoneUtil::getTimeZone('FooBar', null, true); } - public function testFallBack() + public function testFallBack(): void { $vobj = <<assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testLjubljanaBug() + public function testLjubljanaBug(): void { $vobj = <<assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testWeirdSystemVLICs() + public function testWeirdSystemVLICs(): void { $vobj = <<assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testPrefixedOffsetExchangeIdentifier() + public function testPrefixedOffsetExchangeIdentifier(): void { $tz = TimeZoneUtil::getTimeZone('(UTC-05:00) Eastern Time (US & Canada)'); $ex = new \DateTimeZone('America/New_York'); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } - public function testMicrosoftMap() + public function testMicrosoftMap(): void { $tz = TimeZoneUtil::getTimeZone('tzone://Microsoft/Utc', null, true); $ex = new \DateTimeZone('UTC'); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } /** * @dataProvider unSupportTimezoneProvider */ - public function testPHPUnSupportTimeZone(string $origin, string $expected) + public function testPHPUnSupportTimeZone(string $origin, string $expected): void { $tz = TimeZoneUtil::getTimeZone($origin, null, true); $ex = new \DateTimeZone($expected); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } public function unSupportTimezoneProvider(): iterable @@ -474,12 +484,12 @@ public function unSupportTimezoneProvider(): iterable 'expected' => 'Asia/Dubai', ]; - if (($handle = fopen(__DIR__ . "/microsoft-timezones-confluence.csv", "r")) !== FALSE) { + if (($handle = fopen(__DIR__.'/microsoft-timezones-confluence.csv', 'r')) !== false) { $data = fgetcsv($handle); - while (($data = fgetcsv($handle)) !== FALSE) { + while (($data = fgetcsv($handle)) !== false) { yield $data[0] => [ 'origin' => $data[0], - 'expected' => $data[2] !== '' ? $data[2] : $data[1], + 'expected' => '' !== $data[2] ? $data[2] : $data[1], ]; } fclose($handle); @@ -489,11 +499,11 @@ public function unSupportTimezoneProvider(): iterable /** * @dataProvider offsetTimeZoneProvider */ - public function testOffsetTimeZones(string $origin, string $expected) + public function testOffsetTimeZones(string $origin, string $expected): void { $tz = TimeZoneUtil::getTimeZone($origin, null, true); $ex = new \DateTimeZone($expected); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } public function offsetTimeZoneProvider(): iterable @@ -522,11 +532,11 @@ public function offsetTimeZoneProvider(): iterable /** * @dataProvider letterCaseTimeZoneProvider */ - public function testDifferentLetterCaseTimeZone(string $origin, string $expected) + public function testDifferentLetterCaseTimeZone(string $origin, string $expected): void { $tz = TimeZoneUtil::getTimeZone($origin, null, true); $ex = new \DateTimeZone($expected); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } public function letterCaseTimeZoneProvider(): iterable @@ -555,11 +565,11 @@ public function letterCaseTimeZoneProvider(): iterable /** * @dataProvider outlookCitiesProvider */ - public function testOutlookCities(string $origin, bool $failIfUncertain, string $expected) + public function testOutlookCities(string $origin, bool $failIfUncertain, string $expected): void { $tz = TimeZoneUtil::getTimeZone($origin, null, $failIfUncertain); $ex = new \DateTimeZone($expected); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } public function outlookCitiesProvider(): iterable @@ -592,11 +602,11 @@ public function outlookCitiesProvider(): iterable /** * @dataProvider versionTzProvider */ - public function testVersionTz(string $origin, bool $failIfUncertain, string $expected) + public function testVersionTz(string $origin, bool $failIfUncertain, string $expected): void { $tz = TimeZoneUtil::getTimeZone($origin, null, $failIfUncertain); $ex = new \DateTimeZone($expected); - $this->assertEquals($ex->getName(), $tz->getName()); + self::assertEquals($ex->getName(), $tz->getName()); } public function versionTzProvider(): iterable @@ -614,7 +624,7 @@ public function versionTzProvider(): iterable ]; } - public function testCustomizedTimeZone() + public function testCustomizedTimeZone(): void { $ics = <<assertNotSame('Customized Time Zone', $tz->getName()); + self::assertNotSame('Customized Time Zone', $tz->getName()); $start = new \DateTimeImmutable('2022-04-25'); - $this->assertSame(10 * 60 * 60, $tz->getOffset($start)); + self::assertSame(10 * 60 * 60, $tz->getOffset($start)); $start = new \DateTimeImmutable('2022-11-10'); - $this->assertSame(11 * 60 * 60, $tz->getOffset($start)); + self::assertSame(11 * 60 * 60, $tz->getOffset($start)); } - public function testCustomizedTimeZoneWithoutDaylight() + public function testCustomizedTimeZoneWithoutDaylight(): void { $ics = $this->getCustomizedICS(); $tz = TimeZoneUtil::getTimeZone('Customized Time Zone', Reader::read($ics)); - $this->assertSame('Asia/Brunei', $tz->getName()); + self::assertSame('Asia/Brunei', $tz->getName()); $start = new \DateTimeImmutable('2022-04-25'); - $this->assertSame(8 * 60 * 60, $tz->getOffset($start)); + self::assertSame(8 * 60 * 60, $tz->getOffset($start)); } - public function testCustomizedTimeZoneFlag() + public function testCustomizedTimeZoneFlag(): void { - $this->expectException(\InvalidArgumentException::class); + self::expectException(\InvalidArgumentException::class); $ics = $this->getCustomizedICS(); $vobject = Reader::read($ics); $vobject->VEVENT->DTSTART->getDateTime(null, false); diff --git a/tests/VObject/UUIDUtilTest.php b/tests/VObject/UUIDUtilTest.php index 579928f38..170107b30 100644 --- a/tests/VObject/UUIDUtilTest.php +++ b/tests/VObject/UUIDUtilTest.php @@ -6,18 +6,18 @@ class UUIDUtilTest extends TestCase { - public function testValidateUUID() + public function testValidateUUID(): void { - $this->assertTrue( + self::assertTrue( UUIDUtil::validateUUID('11111111-2222-3333-4444-555555555555') ); - $this->assertFalse( + self::assertFalse( UUIDUtil::validateUUID(' 11111111-2222-3333-4444-555555555555') ); - $this->assertTrue( + self::assertTrue( UUIDUtil::validateUUID('ffffffff-2222-3333-4444-555555555555') ); - $this->assertFalse( + self::assertFalse( UUIDUtil::validateUUID('fffffffg-2222-3333-4444-555555555555') ); } @@ -25,9 +25,9 @@ public function testValidateUUID() /** * @depends testValidateUUID */ - public function testGetUUID() + public function testGetUUID(): void { - $this->assertTrue( + self::assertTrue( UUIDUtil::validateUUID( UUIDUtil::getUUID() ) diff --git a/tests/VObject/VCard21Test.php b/tests/VObject/VCard21Test.php index 9dd07288e..d091e35d0 100644 --- a/tests/VObject/VCard21Test.php +++ b/tests/VObject/VCard21Test.php @@ -9,7 +9,7 @@ */ class VCard21Test extends TestCase { - public function testPropertyWithNoName() + public function testPropertyWithNoName(): void { $input = <<serialize(); - $this->assertEquals($input, $output); + self::assertEquals($input, $output); } - public function testPropertyPadValueCount() + public function testPropertyPadValueCount(): void { $input = <<assertEquals($expected, $output); + self::assertEquals($expected, $output); } } diff --git a/tests/VObject/VCardConverterTest.php b/tests/VObject/VCardConverterTest.php index ae2b10bd5..949a102a7 100644 --- a/tests/VObject/VCardConverterTest.php +++ b/tests/VObject/VCardConverterTest.php @@ -3,12 +3,16 @@ namespace Sabre\VObject; use PHPUnit\Framework\TestCase; +use Sabre\VObject\Component\VCard; class VCardConverterTest extends TestCase { - use \Sabre\VObject\PHPUnitAssertions; + use PHPUnitAssertions; - public function testConvert30to40() + /** + * @throws InvalidDataException + */ + public function testConvert30to40(): void { $input = <<convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testConvert40to40() + /** + * @throws InvalidDataException + */ + public function testConvert40to40(): void { $input = <<convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testConvert21to40() + /** + * @throws InvalidDataException + */ + public function testConvert21to40(): void { $input = <<convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testConvert30to30() + /** + * @throws InvalidDataException + */ + public function testConvert30to30(): void { $input = <<convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testConvert40to30() + /** + * @throws InvalidDataException + */ + public function testConvert40to30(): void { $input = <<convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testConvertGroupCard() + /** + * @throws InvalidDataException + */ + public function testConvertGroupCard(): void { $input = <<convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); @@ -236,20 +265,26 @@ public function testConvertGroupCard() BEGIN:VCARD VERSION:3.0 X-ADDRESSBOOKSERVER-KIND:GROUP +X-ADDRESSBOOKSERVER-MEMBER:mailto:someone@example.com +X-ADDRESSBOOKSERVER-MEMBER:mailto:sometwo@example.com END:VCARD OUT; + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testBDAYConversion() + /** + * @throws InvalidDataException + */ + public function testBDAYConversion(): void { $input = <<convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); @@ -285,16 +321,20 @@ public function testBDAYConversion() OUT; + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testUnknownSourceVCardVersion() + /** + * @throws InvalidDataException + */ + public function testUnknownSourceVCardVersion(): void { $this->expectException(\InvalidArgumentException::class); $input = <<convert(Document::VCARD40); } - public function testUnknownTargetVCardVersion() + /** + * @throws InvalidDataException + */ + public function testUnknownTargetVCardVersion(): void { $this->expectException(\InvalidArgumentException::class); $input = <<convert(Document::VCARD21); } - public function testConvertIndividualCard() + /** + * @throws InvalidDataException + */ + public function testConvertIndividualCard(): void { $input = <<convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); @@ -367,16 +416,20 @@ public function testConvertIndividualCard() OUT; + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testAnniversary() + /** + * @throws InvalidDataException + */ + public function testAnniversary(): void { $input = <<convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); @@ -413,16 +467,20 @@ public function testAnniversary() $input, ]; + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testMultipleAnniversaries() + /** + * @throws InvalidDataException + */ + public function testMultipleAnniversaries(): void { $input = <<convert(Document::VCARD30); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); @@ -467,16 +526,20 @@ public function testMultipleAnniversaries() $input, ]; + /** @var VCard $vcard */ $vcard = Reader::read($input); $vcard = $vcard->convert(Document::VCARD40); - $this->assertVObjectEqualsVObject( + self::assertVObjectEqualsVObject( $output, $vcard ); } - public function testNoLabel() + /** + * @throws InvalidDataException + */ + public function testNoLabel(): void { $input = <<assertInstanceOf(Component\VCard::class, $vcard); + self::assertInstanceOf(Component\VCard::class, $vcard); + /** @var VCard $vcard */ $vcard = $vcard->convert(Document::VCARD40); $vcard = $vcard->serialize(); + /** @var VCard $converted */ $converted = Reader::read($vcard); $converted->validate(); @@ -512,10 +577,13 @@ public function testNoLabel() VCF; - $this->assertEquals($expected, str_replace("\r", '', $vcard)); + self::assertEquals($expected, str_replace("\r", '', $vcard)); } - public function testPhoneNumberValueTypeGetsRemoved() + /** + * @throws InvalidDataException + */ + public function testPhoneNumberValueTypeGetsRemoved(): void { $input = <<convert(Document::VCARD40); diff --git a/tests/VObject/VersionTest.php b/tests/VObject/VersionTest.php index 0ad9627f8..f2f240ebc 100644 --- a/tests/VObject/VersionTest.php +++ b/tests/VObject/VersionTest.php @@ -6,9 +6,9 @@ class VersionTest extends TestCase { - public function testString() + public function testString(): void { $v = Version::VERSION; - $this->assertEquals(-1, version_compare('2.0.0', $v)); + self::assertEquals(-1, version_compare('2.0.0', $v)); } } diff --git a/tests/VObject/WriterTest.php b/tests/VObject/WriterTest.php index e30fac501..f5cd7a69a 100644 --- a/tests/VObject/WriterTest.php +++ b/tests/VObject/WriterTest.php @@ -6,29 +6,29 @@ class WriterTest extends TestCase { - public function getComponent() + public function getComponent(): ?Document { $data = "BEGIN:VCALENDAR\r\nEND:VCALENDAR"; return Reader::read($data); } - public function testWriteToMimeDir() + public function testWriteToMimeDir(): void { $result = Writer::write($this->getComponent()); - $this->assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $result); + self::assertEquals("BEGIN:VCALENDAR\r\nEND:VCALENDAR\r\n", $result); } - public function testWriteToJson() + public function testWriteToJson(): void { $result = Writer::writeJson($this->getComponent()); - $this->assertEquals('["vcalendar",[],[]]', $result); + self::assertEquals('["vcalendar",[],[]]', $result); } - public function testWriteToXml() + public function testWriteToXml(): void { $result = Writer::writeXml($this->getComponent()); - $this->assertEquals( + self::assertEquals( ''."\n". ''."\n". ' '."\n". diff --git a/tests/phpunit.xml b/tests/phpunit.xml index c0588d460..01ba374c1 100644 --- a/tests/phpunit.xml +++ b/tests/phpunit.xml @@ -6,16 +6,21 @@ convertWarningsToExceptions="true" beStrictAboutTestsThatDoNotTestAnything="true" beStrictAboutOutputDuringTests="true" + failOnRisky="true" + failOnWarning="true" + enforceTimeLimit="true" > + + + + + + ../lib/ + + . - - - - ../lib/ - -