[Pkg-owncloud-commits] [php-sabre-vobject] 18/46: Using InvalidDataException whereever it makes sense
David Prévot
taffit at moszumanska.debian.org
Thu Dec 10 02:12:39 UTC 2015
This is an automated email from the git hooks/post-receive script.
taffit pushed a commit to branch master
in repository php-sabre-vobject.
commit 20385324f2c6cdb8912b0e8aae2ce7492a0dc019
Author: Evert Pot <me at evertpot.com>
Date: Wed Nov 25 21:05:37 2015 -0500
Using InvalidDataException whereever it makes sense
---
lib/BirthdayCalendarGenerator.php | 2 +-
lib/Component/VAlarm.php | 3 ++-
lib/DateTimeParser.php | 12 ++++++------
lib/Property/ICalendar/DateTime.php | 5 +++--
lib/Property/VCard/DateAndOrTime.php | 9 +++++----
lib/Recur/RRuleIterator.php | 9 +++++----
tests/VObject/Component/VAlarmTest.php | 2 +-
tests/VObject/DateTimeParserTest.php | 10 +++++-----
tests/VObject/Property/ICalendar/DateTimeTest.php | 2 +-
.../VObject/Recur/EventIterator/InfiniteLoopProblemTest.php | 2 +-
tests/VObject/{ => Recur/EventIterator}/Issue26Test.php | 9 ++++++---
tests/VObject/Recur/EventIterator/MainTest.php | 2 +-
tests/VObject/Recur/RRuleIteratorTest.php | 8 ++++----
13 files changed, 41 insertions(+), 34 deletions(-)
diff --git a/lib/BirthdayCalendarGenerator.php b/lib/BirthdayCalendarGenerator.php
index f93030e..16f080e 100644
--- a/lib/BirthdayCalendarGenerator.php
+++ b/lib/BirthdayCalendarGenerator.php
@@ -144,7 +144,7 @@ class BirthdayCalendarGenerator {
// Skip if we can't parse the BDAY value.
try {
$dateParts = DateTimeParser::parseVCardDateTime($object->BDAY->getValue());
- } catch (\InvalidArgumentException $e) {
+ } catch (InvalidDataException $e) {
continue;
}
diff --git a/lib/Component/VAlarm.php b/lib/Component/VAlarm.php
index 5fd134f..954735c 100644
--- a/lib/Component/VAlarm.php
+++ b/lib/Component/VAlarm.php
@@ -3,6 +3,7 @@
namespace Sabre\VObject\Component;
use Sabre\VObject;
+use Sabre\VObject\InvalidDataException;
use DateTimeInterface;
use DateTimeImmutable;
@@ -48,7 +49,7 @@ class VAlarm extends VObject\Component {
} elseif ($parentComponent->name === 'VEVENT') {
$endProp = 'DTEND';
} else {
- throw new \LogicException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
+ throw new InvalidDataException('time-range filters on VALARM components are only supported when they are a child of VTODO or VEVENT');
}
if (isset($parentComponent->$endProp)) {
diff --git a/lib/DateTimeParser.php b/lib/DateTimeParser.php
index 0fe8143..a12b776 100644
--- a/lib/DateTimeParser.php
+++ b/lib/DateTimeParser.php
@@ -39,7 +39,7 @@ class DateTimeParser {
$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);
if (!$result) {
- throw new LogicException('The supplied iCalendar datetime value is incorrect: ' . $dt);
+ throw new InvalidDataException('The supplied iCalendar datetime value is incorrect: ' . $dt);
}
if ($matches[7] === 'Z' || is_null($tz)) {
@@ -65,7 +65,7 @@ class DateTimeParser {
$result = preg_match('/^([0-9]{4})([0-1][0-9])([0-3][0-9])$/', $date, $matches);
if (!$result) {
- throw new LogicException('The supplied iCalendar date value is incorrect: ' . $date);
+ throw new InvalidDataException('The supplied iCalendar date value is incorrect: ' . $date);
}
if (is_null($tz)) {
@@ -93,7 +93,7 @@ class DateTimeParser {
$result = preg_match('/^(?<plusminus>\+|-)?P((?<week>\d+)W)?((?<day>\d+)D)?(T((?<hour>\d+)H)?((?<minute>\d+)M)?((?<second>\d+)S)?)?$/', $duration, $matches);
if (!$result) {
- throw new LogicException('The supplied iCalendar duration value is incorrect: ' . $duration);
+ throw new InvalidDataException('The supplied iCalendar duration value is incorrect: ' . $duration);
}
if (!$asString) {
@@ -314,7 +314,7 @@ class DateTimeParser {
$/x';
if (!preg_match($regex, $date, $matches)) {
- throw new InvalidArgumentException('Invalid vCard date-time string: ' . $date);
+ throw new InvalidDataException('Invalid vCard date-time string: ' . $date);
}
}
@@ -420,7 +420,7 @@ class DateTimeParser {
$/x';
if (!preg_match($regex, $date, $matches)) {
- throw new InvalidArgumentException('Invalid vCard time string: ' . $date);
+ throw new InvalidDataException('Invalid vCard time string: ' . $date);
}
}
@@ -533,7 +533,7 @@ class DateTimeParser {
if (0 === preg_match($valueDate, $date, $matches)
&& 0 === preg_match($valueDateTime, $date, $matches)
&& 0 === preg_match($valueTime, $date, $matches)) {
- throw new InvalidArgumentException('Invalid vCard date-time string: ' . $date);
+ throw new InvalidDataException('Invalid vCard date-time string: ' . $date);
}
$parts = [
diff --git a/lib/Property/ICalendar/DateTime.php b/lib/Property/ICalendar/DateTime.php
index a7e29af..544f447 100644
--- a/lib/Property/ICalendar/DateTime.php
+++ b/lib/Property/ICalendar/DateTime.php
@@ -4,8 +4,9 @@ namespace Sabre\VObject\Property\ICalendar;
use DateTimeInterface;
use DateTimeZone;
-use Sabre\VObject\Property;
use Sabre\VObject\DateTimeParser;
+use Sabre\VObject\InvalidDataException;
+use Sabre\VObject\Property;
use Sabre\VObject\TimeZoneUtil;
/**
@@ -390,7 +391,7 @@ class DateTime extends Property {
break;
}
}
- } catch (\LogicException $e) {
+ } catch (InvalidDataException $e) {
$messages[] = [
'level' => 3,
'message' => 'The supplied value (' . $value . ') is not a correct ' . $valueType,
diff --git a/lib/Property/VCard/DateAndOrTime.php b/lib/Property/VCard/DateAndOrTime.php
index 3560884..f188a2e 100644
--- a/lib/Property/VCard/DateAndOrTime.php
+++ b/lib/Property/VCard/DateAndOrTime.php
@@ -2,12 +2,13 @@
namespace Sabre\VObject\Property\VCard;
-use Sabre\VObject\DateTimeParser;
-use Sabre\VObject\Property;
-use Sabre\Xml;
use DateTimeInterface;
use DateTimeImmutable;
use DateTime;
+use Sabre\VObject\DateTimeParser;
+use Sabre\VObject\InvalidDataException;
+use Sabre\VObject\Property;
+use Sabre\Xml;
/**
* DateAndOrTime property.
@@ -393,7 +394,7 @@ class DateAndOrTime extends Property {
try {
DateTimeParser::parseVCardDateTime($value);
- } catch (\InvalidArgumentException $e) {
+ } catch (InvalidDataException $e) {
$messages[] = [
'level' => 3,
'message' => 'The supplied value (' . $value . ') is not a correct DATE-AND-OR-TIME property',
diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php
index 27f5939..9adc61f 100644
--- a/lib/Recur/RRuleIterator.php
+++ b/lib/Recur/RRuleIterator.php
@@ -7,6 +7,7 @@ use DateTimeImmutable;
use InvalidArgumentException;
use Iterator;
use Sabre\VObject\DateTimeParser;
+use Sabre\VObject\InvalidDataException;
use Sabre\VObject\Property;
/**
@@ -649,7 +650,7 @@ class RRuleIterator implements Iterator {
$value,
['secondly', 'minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly']
)) {
- throw new InvalidArgumentException('Unknown value for FREQ=' . strtoupper($value));
+ throw new InvalidDataException('Unknown value for FREQ=' . strtoupper($value));
}
$this->frequency = $value;
break;
@@ -676,7 +677,7 @@ class RRuleIterator implements Iterator {
case 'COUNT' :
$val = (int)$value;
if ($val < 1) {
- throw new \InvalidArgumentException(strtoupper($key) . ' in RRULE must be a positive integer!');
+ throw new InvalidDataException(strtoupper($key) . ' in RRULE must be a positive integer!');
}
$key = strtolower($key);
$this->$key = $val;
@@ -698,7 +699,7 @@ class RRuleIterator implements Iterator {
$value = (array)$value;
foreach ($value as $part) {
if (!preg_match('#^ (-|\+)? ([1-5])? (MO|TU|WE|TH|FR|SA|SU) $# xi', $part)) {
- throw new \InvalidArgumentException('Invalid part in BYDAY clause: ' . $part);
+ throw new InvalidDataException('Invalid part in BYDAY clause: ' . $part);
}
}
$this->byDay = $value;
@@ -729,7 +730,7 @@ class RRuleIterator implements Iterator {
break;
default:
- throw new \InvalidArgumentException('Not supported: ' . strtoupper($key));
+ throw new InvalidDataException('Not supported: ' . strtoupper($key));
}
diff --git a/tests/VObject/Component/VAlarmTest.php b/tests/VObject/Component/VAlarmTest.php
index 8732aeb..b398e71 100644
--- a/tests/VObject/Component/VAlarmTest.php
+++ b/tests/VObject/Component/VAlarmTest.php
@@ -129,7 +129,7 @@ class VAlarmTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException LogicException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testInTimeRangeInvalidComponent() {
diff --git a/tests/VObject/DateTimeParserTest.php b/tests/VObject/DateTimeParserTest.php
index 35fe23f..3b9e9c3 100644
--- a/tests/VObject/DateTimeParserTest.php
+++ b/tests/VObject/DateTimeParserTest.php
@@ -33,7 +33,7 @@ class DateTimeParserTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException LogicException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testParseICalendarDurationFail() {
@@ -53,7 +53,7 @@ class DateTimeParserTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testParseICalendarDateTime
- * @expectedException LogicException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testParseICalendarDateTimeBadFormat() {
@@ -144,7 +144,7 @@ class DateTimeParserTest extends \PHPUnit_Framework_TestCase {
/**
* @depends testParseICalendarDate
- * @expectedException LogicException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testParseICalendarDateBadFormat() {
@@ -166,7 +166,7 @@ class DateTimeParserTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider vcardDates
- * @expectedException \InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testBadVCardDate() {
@@ -176,7 +176,7 @@ class DateTimeParserTest extends \PHPUnit_Framework_TestCase {
/**
* @dataProvider vcardDates
- * @expectedException \InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testBadVCardTime() {
diff --git a/tests/VObject/Property/ICalendar/DateTimeTest.php b/tests/VObject/Property/ICalendar/DateTimeTest.php
index 3f35b92..c89cfe6 100644
--- a/tests/VObject/Property/ICalendar/DateTimeTest.php
+++ b/tests/VObject/Property/ICalendar/DateTimeTest.php
@@ -270,7 +270,7 @@ class DateTimeTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException LogicException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testGetDateTimeDateInvalid() {
diff --git a/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php b/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php
index d3de196..8b0e480 100644
--- a/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php
+++ b/tests/VObject/Recur/EventIterator/InfiniteLoopProblemTest.php
@@ -77,7 +77,7 @@ class InfiniteLoopProblemTest extends \PHPUnit_Framework_TestCase {
* this means we increase the current day (or week, month) by 0, this also
* results in an infinite loop.
*
- * @expectedException InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
* @return void
*/
function testZeroInterval() {
diff --git a/tests/VObject/Issue26Test.php b/tests/VObject/Recur/EventIterator/Issue26Test.php
similarity index 68%
rename from tests/VObject/Issue26Test.php
rename to tests/VObject/Recur/EventIterator/Issue26Test.php
index 6dda212..693a890 100644
--- a/tests/VObject/Issue26Test.php
+++ b/tests/VObject/Recur/EventIterator/Issue26Test.php
@@ -1,11 +1,14 @@
<?php
-namespace Sabre\VObject;
+namespace Sabre\VObject\Recur\EventIterator;
+
+use Sabre\VObject\Reader;
+use Sabre\VObject\Recur\EventIterator;
class Issue26Test extends \PHPUnit_Framework_TestCase {
/**
- * @expectedException \InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testExpand() {
@@ -24,7 +27,7 @@ ICS;
$vcal = Reader::read($input);
$this->assertInstanceOf('Sabre\\VObject\\Component\\VCalendar', $vcal);
- $it = new Recur\EventIterator($vcal, 'bae5d57a98');
+ $it = new EventIterator($vcal, 'bae5d57a98');
iterator_to_array($it);
}
diff --git a/tests/VObject/Recur/EventIterator/MainTest.php b/tests/VObject/Recur/EventIterator/MainTest.php
index f3fee05..28eec5d 100644
--- a/tests/VObject/Recur/EventIterator/MainTest.php
+++ b/tests/VObject/Recur/EventIterator/MainTest.php
@@ -29,7 +29,7 @@ class MainTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
* @depends testValues
*/
function testInvalidFreq() {
diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php
index 3b1e6ac..463757b 100644
--- a/tests/VObject/Recur/RRuleIteratorTest.php
+++ b/tests/VObject/Recur/RRuleIteratorTest.php
@@ -541,7 +541,7 @@ class RRuleIteratorTest extends \PHPUnit_Framework_TestCase {
* this means we increase the current day (or week, month) by 0, this also
* results in an infinite loop.
*
- * @expectedException InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testZeroInterval() {
@@ -555,7 +555,7 @@ class RRuleIteratorTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testInvalidFreq() {
@@ -568,7 +568,7 @@ class RRuleIteratorTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testByDayBadOffset() {
@@ -643,7 +643,7 @@ class RRuleIteratorTest extends \PHPUnit_Framework_TestCase {
}
/**
- * @expectedException InvalidArgumentException
+ * @expectedException \Sabre\VObject\InvalidDataException
*/
function testUnsupportedPart() {
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/php-sabre-vobject.git
More information about the Pkg-owncloud-commits
mailing list