Skip to content

Commit

Permalink
Modernize code
Browse files Browse the repository at this point in the history
* Require PHP 7.4
* Add typing everywhere possible
* Small internal improvements

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
  • Loading branch information
tcitworld authored and phil-davis committed Aug 19, 2022
1 parent d1fdc0c commit 87037b2
Show file tree
Hide file tree
Showing 80 changed files with 1,295 additions and 1,636 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ tests/temp
tests/.phpunit.result.cache

# Development stuff
.php_cs.cache
.php-cs-fixer.cache
2 changes: 1 addition & 1 deletion .php_cs.dist → .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

$config = PhpCsFixer\Config::create();
$config = new PhpCsFixer\Config();
$config->getFinder()
->exclude('vendor')
->in(__DIR__);
Expand Down
9 changes: 5 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" : "*",
"ext-json" : "*",
"sabre/xml" : "^2.1"
},
"require-dev" : {
"friendsofphp/php-cs-fixer": "~2.17.1",
"friendsofphp/php-cs-fixer": "^3.5.0",
"phpunit/phpunit" : "^7.5 || ^8.5 || ^9.0",
"phpunit/php-invoker" : "^2.0 || ^3.1",
"phpstan/phpstan": "^0.12"
"phpstan/phpstan": "^1.4.2"
},
"suggest" : {
"hoa/bench" : "If you would like to run the benchmark scripts"
Expand Down Expand Up @@ -90,7 +91,7 @@
},
"scripts": {
"phpstan": [
"phpstan analyse lib tests"
"phpstan analyse lib tests --memory-limit 1G"
],
"cs-fixer": [
"php-cs-fixer fix"
Expand Down
22 changes: 11 additions & 11 deletions lib/BirthdayCalendarGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

namespace Sabre\VObject;

use DateTime;
use InvalidArgumentException;
use Sabre\VObject\Component\VCalendar;
use Sabre\VObject\Component\VEvent;

/**
* This class generates birthday calendars.
Expand All @@ -24,7 +27,7 @@ class BirthdayCalendarGenerator
* Default year.
* Used for dates without a year.
*/
const DEFAULT_YEAR = 2000;
public const DEFAULT_YEAR = 2000;

/**
* Output format for the SUMMARY.
Expand Down Expand Up @@ -56,7 +59,7 @@ public function __construct($objects = null)
*
* @param mixed $objects
*/
public function setObjects($objects)
public function setObjects($objects): void
{
if (!is_array($objects)) {
$objects = [$objects];
Expand All @@ -67,34 +70,30 @@ public function setObjects($objects)
if (is_string($object)) {
$vObj = Reader::read($object);
if (!$vObj instanceof Component\VCard) {
throw new \InvalidArgumentException('String could not be parsed as \\Sabre\\VObject\\Component\\VCard by setObjects');
throw new InvalidArgumentException('String could not be parsed as \\Sabre\\VObject\\Component\\VCard by setObjects');
}

$this->objects[] = $vObj;
} elseif ($object instanceof Component\VCard) {
$this->objects[] = $object;
} else {
throw new \InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component\\VCard arguments to setObjects');
throw new InvalidArgumentException('You can only pass strings or \\Sabre\\VObject\\Component\\VCard arguments to setObjects');
}
}
}

/**
* 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();

Expand Down Expand Up @@ -142,9 +141,10 @@ public function getResult()
}

// Create event.
/** @var VEvent $event */
$event = $calendar->add('VEVENT', [
'SUMMARY' => sprintf($this->format, $object->FN->getValue()),
'DTSTART' => new \DateTime($object->BDAY->getValue()),
'DTSTART' => new DateTime($object->BDAY->getValue()),
'RRULE' => 'FREQ=YEARLY',
'TRANSP' => 'TRANSPARENT',
]);
Expand Down
Loading

0 comments on commit 87037b2

Please sign in to comment.