Skip to content

Commit

Permalink
Lots of small cleanups.
Browse files Browse the repository at this point in the history
Thanks @jakobsack!
Closes #263.
  • Loading branch information
evert committed Nov 26, 2015
1 parent ee615b0 commit 24b48ff
Show file tree
Hide file tree
Showing 9 changed files with 22 additions and 13 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ ChangeLog
because there was something wrong with input data.
* #227: Always add `VALUE=URI` to `PHOTO` properties.
* #235: Always add `VALUE=URI` to `URL` properties.
* It's now possible to override which class is used instead of
`Component\VCalendar` or `Component\VCard` during parsing.
* #263: Lots of small cleanups. (@jakobsack)


4.0.0-alpha2 (2015-09-04)
Expand Down
2 changes: 1 addition & 1 deletion lib/Component/VAlarm.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end) {

if (isset($this->DURATION)) {
$duration = VObject\DateTimeParser::parseDuration($this->DURATION);
$repeat = (string)$this->repeat;
$repeat = (string)$this->REPEAT;
if (!$repeat) {
$repeat = 1;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/Component/VCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class VCalendar extends VObject\Document {
* @var array
*/
static $componentMap = [
'VCALENDAR' => 'Sabre\\VObject\\Component\\VCalendar',
'VALARM' => 'Sabre\\VObject\\Component\\VAlarm',
'VEVENT' => 'Sabre\\VObject\\Component\\VEvent',
'VFREEBUSY' => 'Sabre\\VObject\\Component\\VFreeBusy',
Expand Down Expand Up @@ -509,7 +510,7 @@ function validate($options = 0) {
'node' => $this,
];
}
if (count(array_unique($componentTypes)) === 0) {
if (count($componentTypes) === 0) {
$warnings[] = [
'level' => 3,
'message' => 'A calendar object on a CalDAV server must have at least 1 component (VTODO, VEVENT, VJOURNAL).',
Expand Down
9 changes: 9 additions & 0 deletions lib/Component/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ class VCard extends VObject\Document {
*/
private $version = null;

/**
* This is a list of components, and which classes they should map to.
*
* @var array
*/
static $componentMap = [
'VCARD' => 'Sabre\\VObject\\Component\\VCard',
];

/**
* List of value-types, and which classes they map to.
*
Expand Down
2 changes: 1 addition & 1 deletion lib/Parameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ static function guessParameterNameByValue($value) {
case 'DIB' :
case 'PICT' :
case 'TIFF' :
case 'PDF ':
case 'PDF':
case 'PS' :
case 'JPEG' :
case 'MPEG' :
Expand Down
8 changes: 2 additions & 6 deletions lib/Parser/MimeDir.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,10 @@ protected function parseDocument() {

switch (strtoupper($line)) {
case 'BEGIN:VCALENDAR' :
$class = isset(VCalendar::$componentMap['VCALENDAR'])
? VCalendar::$componentMap[$name]
: 'Sabre\\VObject\\Component\\VCalendar';
$class = VCalendar::$componentMap['VCALENDAR'];
break;
case 'BEGIN:VCARD' :
$class = isset(VCard::$componentMap['VCARD'])
? VCard::$componentMap['VCARD']
: 'Sabre\\VObject\\Component\\VCard';
$class = VCard::$componentMap['VCARD'];
break;
default :
throw new ParseException('This parser only supports VCARD and VCALENDAR files');
Expand Down
2 changes: 1 addition & 1 deletion lib/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ function getValue() {
} elseif (count($this->value) === 1) {
return $this->value[0];
} else {
return $this->getRawMimeDirValue($this->value);
return $this->getRawMimeDirValue();
}
} else {
return $this->value;
Expand Down
2 changes: 1 addition & 1 deletion tests/VObject/PropertyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ function testValidateControlChars() {
$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( )08()07()06()05()04()03()02()01()00()]end", $property->getRawMimeDirValue());
$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());

}

Expand Down
4 changes: 2 additions & 2 deletions tests/VObject/ReaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ function testReadPropertyParameterNewLines() {
$data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=paramvalue1^nvalue2^^nvalue3:propValue\r\nEND:VCALENDAR";
$result = Reader::read($data);

$result = $result->propname;
$result = $result->PROPNAME;

$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
Expand All @@ -318,7 +318,7 @@ function testReadPropertyParameterQuotedColon() {

$data = "BEGIN:VCALENDAR\r\nPROPNAME;PARAMNAME=\"param:value\":propValue\r\nEND:VCALENDAR";
$result = Reader::read($data);
$result = $result->propname;
$result = $result->PROPNAME;

$this->assertInstanceOf('Sabre\\VObject\\Property', $result);
$this->assertEquals('PROPNAME', $result->name);
Expand Down

0 comments on commit 24b48ff

Please sign in to comment.