Commit 31dba7b7 authored by Markus Poerschke's avatar Markus Poerschke

Apply code style for PHP 7 and test style on Travis CI

parent fa91b4c2
/.php_cs.cache
/composer.lock
/vendor
<?php
Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader(<<<EOF
$headerComment = <<<EOF
This file is part of the eluceo/iCal package.
(c) Markus Poerschke <markus@eluceo.de>
This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF
);
EOF;
$finder = Symfony\CS\Finder\DefaultFinder::create();
$finder->in(__DIR__ . '/src');
$finder = PhpCsFixer\Finder::create()->in(__DIR__ . '/src');
return Symfony\CS\Config\Config::create()
->fixers(array(
'header_comment',
'concat_with_spaces',
'align_equals',
'align_double_arrow',
'unused_use',
'long_array_syntax',
))
->finder($finder)
return PhpCsFixer\Config::create()
->setRules([
'@Symfony' => true,
'ordered_imports' => true,
'concat_space' => ['spacing' => 'one'],
'array_syntax' => ['syntax' => 'short'],
'header_comment' => ['header' => $headerComment]
])
->setFinder($finder)
;
......@@ -13,9 +13,11 @@ cache:
before_script:
- travis_retry composer self-update
- travis_retry composer install --no-interaction --prefer-dist
- travis_retry wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar
script:
- ./vendor/bin/phpunit --coverage-clover=coverage.clover
- php php-cs-fixer-v2.phar fix --dry-run --diff
after_script:
- travis_retry wget https://scrutinizer-ci.com/ocular.phar
......
......@@ -12,3 +12,12 @@ This project uses unit tests to keep the quality of this package high. If you ca
Before you can execute your unit tests you have to install the required PHPUnit version by running `composer update`.
Run `composer test` on your command line to execute the unit tests.
### Code Style
This project uses the [PHP Coding Standards Fixer](http://cs.sensiolabs.org/). To fix or to check the code stlye
download the tool and execute it on your command line:
```
php ./php-cs-fixer-v2.phar fix
```
......@@ -23,7 +23,7 @@ abstract class Component
*
* @var Component[]
*/
protected $components = array();
protected $components = [];
/**
* The order in which the components will be rendered during build.
......@@ -32,7 +32,7 @@ abstract class Component
*
* @var array
*/
private $componentsBuildOrder = array('VTIMEZONE', 'DAYLIGHT', 'STANDARD');
private $componentsBuildOrder = ['VTIMEZONE', 'DAYLIGHT', 'STANDARD'];
/**
* The type of the concrete Component.
......@@ -76,7 +76,7 @@ abstract class Component
*/
public function build()
{
$lines = array();
$lines = [];
$lines[] = sprintf('BEGIN:%s', $this->getType());
......@@ -91,7 +91,7 @@ abstract class Component
$lines[] = sprintf('END:%s', $this->getType());
$ret = array();
$ret = [];
foreach ($lines as $line) {
foreach (ComponentUtil::fold($line) as $l) {
......@@ -129,13 +129,13 @@ abstract class Component
*/
private function buildComponents(array &$lines)
{
$componentsByType = array();
$componentsByType = [];
/** @var $component Component */
foreach ($this->components as $component) {
$type = $component->getType();
if (!isset($componentsByType[$type])) {
$componentsByType[$type] = array();
$componentsByType[$type] = [];
}
$componentsByType[$type][] = $component;
}
......
......@@ -12,8 +12,8 @@
namespace Eluceo\iCal\Component;
use Eluceo\iCal\Component;
use Eluceo\iCal\PropertyBag;
use Eluceo\iCal\Property;
use Eluceo\iCal\PropertyBag;
/**
* Implementation of the VALARM component.
......@@ -25,11 +25,11 @@ class Alarm extends Component
*
* According to RFC 5545: 3.8.6.1. Action
*
* @link http://tools.ietf.org/html/rfc5545#section-3.8.6.1
* @see http://tools.ietf.org/html/rfc5545#section-3.8.6.1
*/
const ACTION_AUDIO = 'AUDIO';
const ACTION_AUDIO = 'AUDIO';
const ACTION_DISPLAY = 'DISPLAY';
const ACTION_EMAIL = 'EMAIL';
const ACTION_EMAIL = 'EMAIL';
protected $action;
protected $repeat;
......
......@@ -21,18 +21,18 @@ class Calendar extends Component
*
* According to RFP 5545: 3.7.2. Method
*
* @link http://tools.ietf.org/html/rfc5545#section-3.7.2
* @see http://tools.ietf.org/html/rfc5545#section-3.7.2
*
* And then according to RFC 2446: 3 APPLICATION PROTOCOL ELEMENTS
* @link https://www.ietf.org/rfc/rfc2446.txt
* @see https://www.ietf.org/rfc/rfc2446.txt
*/
const METHOD_PUBLISH = 'PUBLISH';
const METHOD_REQUEST = 'REQUEST';
const METHOD_REPLY = 'REPLY';
const METHOD_ADD = 'ADD';
const METHOD_CANCEL = 'CANCEL';
const METHOD_REFRESH = 'REFRESH';
const METHOD_COUNTER = 'COUNTER';
const METHOD_PUBLISH = 'PUBLISH';
const METHOD_REQUEST = 'REQUEST';
const METHOD_REPLY = 'REPLY';
const METHOD_ADD = 'ADD';
const METHOD_CANCEL = 'CANCEL';
const METHOD_REFRESH = 'REFRESH';
const METHOD_COUNTER = 'COUNTER';
const METHOD_DECLINECOUNTER = 'DECLINECOUNTER';
/**
......@@ -40,7 +40,7 @@ class Calendar extends Component
*
* According to RFC 5545: 3.7.1. Calendar Scale
*
* @link http://tools.ietf.org/html/rfc5545#section-3.7
* @see http://tools.ietf.org/html/rfc5545#section-3.7
*/
const CALSCALE_GREGORIAN = 'GREGORIAN';
......@@ -51,15 +51,15 @@ class Calendar extends Component
*
* This property specifies the identifier for the product that created the Calendar object.
*
* @link http://www.ietf.org/rfc/rfc2445.txt
* @see http://www.ietf.org/rfc/rfc2445.txt
*
* @var string
*/
protected $prodId = null;
protected $method = null;
protected $name = null;
protected $prodId = null;
protected $method = null;
protected $name = null;
protected $description = null;
protected $timezone = null;
protected $timezone = null;
/**
* This property defines the calendar scale used for the
......
......@@ -14,20 +14,20 @@ namespace Eluceo\iCal\Component;
use Eluceo\iCal\Component;
use Eluceo\iCal\Property;
use Eluceo\iCal\Property\DateTimeProperty;
use Eluceo\iCal\Property\DateTimesProperty;
use Eluceo\iCal\Property\Event\Attendees;
use Eluceo\iCal\Property\Event\Description;
use Eluceo\iCal\Property\Event\Organizer;
use Eluceo\iCal\Property\Event\RecurrenceId;
use Eluceo\iCal\Property\Event\RecurrenceRule;
use Eluceo\iCal\Property\Event\Description;
use Eluceo\iCal\PropertyBag;
use Eluceo\iCal\Property\Event\RecurrenceId;
use Eluceo\iCal\Property\DateTimesProperty;
/**
* Implementation of the EVENT component.
*/
class Event extends Component
{
const TIME_TRANSPARENCY_OPAQUE = 'OPAQUE';
const TIME_TRANSPARENCY_OPAQUE = 'OPAQUE';
const TIME_TRANSPARENCY_TRANSPARENT = 'TRANSPARENT';
const STATUS_TENTATIVE = 'TENTATIVE';
......@@ -148,7 +148,7 @@ class Event extends Component
/**
* @var array
*/
protected $recurrenceRules = array();
protected $recurrenceRules = [];
/**
* This property specifies the date and time that the calendar
......@@ -205,7 +205,7 @@ class Event extends Component
*
* @var \DateTime[]
*/
protected $exDates = array();
protected $exDates = [];
/**
* @var RecurrenceId
......@@ -249,7 +249,7 @@ class Event extends Component
// An event can have a 'dtend' or 'duration', but not both.
if (null != $this->dtEnd) {
if($this->noTime === true) {
if ($this->noTime === true) {
$this->dtEnd->add(new \DateInterval('P1D'));
}
$propertyBag->add(new DateTimeProperty('DTEND', $this->dtEnd, $this->noTime, $this->useTimezone, $this->useUtc));
......@@ -270,12 +270,12 @@ class Event extends Component
new Property(
'X-APPLE-STRUCTURED-LOCATION',
'geo:' . $this->locationGeo,
array(
'VALUE' => 'URI',
'X-ADDRESS' => $this->location,
[
'VALUE' => 'URI',
'X-ADDRESS' => $this->location,
'X-APPLE-RADIUS' => 49,
'X-TITLE' => $this->locationTitle,
)
'X-TITLE' => $this->locationTitle,
]
)
);
$propertyBag->set('GEO', str_replace(',', ';', $this->locationGeo));
......@@ -301,9 +301,9 @@ class Event extends Component
new Property(
'X-ALT-DESC',
$this->descriptionHTML,
array(
[
'FMTTYPE' => 'text/html',
)
]
)
);
}
......@@ -418,9 +418,9 @@ class Event extends Component
*/
public function setLocation($location, $title = '', $geo = null)
{
$this->location = $location;
$this->location = $location;
$this->locationTitle = $title;
$this->locationGeo = $geo;
$this->locationGeo = $geo;
return $this;
}
......@@ -551,7 +551,7 @@ class Event extends Component
*
* @return $this
*/
public function addAttendee($attendee, $params = array())
public function addAttendee($attendee, $params = [])
{
if (!isset($this->attendees)) {
$this->attendees = new Attendees();
......
......@@ -12,8 +12,8 @@
namespace Eluceo\iCal\Component;
use Eluceo\iCal\Component;
use Eluceo\iCal\PropertyBag;
use Eluceo\iCal\Property\Event\RecurrenceRule;
use Eluceo\iCal\PropertyBag;
/**
* Implementation of Standard Time and Daylight Saving Time observances (or rules)
......
......@@ -20,7 +20,7 @@ class ParameterBag
*/
protected $params;
public function __construct($params = array())
public function __construct($params = [])
{
$this->params = $params;
}
......@@ -62,7 +62,7 @@ class ParameterBag
$line = '';
foreach ($this->params as $param => $paramValues) {
if (!is_array($paramValues)) {
$paramValues = array($paramValues);
$paramValues = [$paramValues];
}
foreach ($paramValues as $k => $v) {
$paramValues[$k] = $this->escapeParamValue($v);
......
......@@ -46,7 +46,7 @@ class Property
* @param $value
* @param array $params
*/
public function __construct($name, $value, $params = array())
public function __construct($name, $value, $params = [])
{
$this->name = $name;
$this->setValue($value);
......@@ -82,7 +82,7 @@ class Property
*/
public function toLines()
{
return array($this->toLine());
return [$this->toLine()];
}
/**
......
......@@ -31,7 +31,7 @@ class DateTimeProperty extends Property
$useUtc = false
) {
$dateString = DateUtil::getDateString($dateTime, $noTime, $useTimezone, $useUtc);
$params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone);
$params = DateUtil::getDefaultParams($dateTime, $noTime, $useTimezone);
parent::__construct($name, $dateString, $params);
}
......
......@@ -25,12 +25,12 @@ class DateTimesProperty extends Property
*/
public function __construct(
$name,
$dateTimes = array(),
$dateTimes = [],
$noTime = false,
$useTimezone = false,
$useUtc = false
) {
$dates = array();
$dates = [];
foreach ($dateTimes as $dateTime) {
$dates[] = DateUtil::getDateString($dateTime, $noTime, $useTimezone, $useUtc);
}
......
......@@ -16,7 +16,7 @@ use Eluceo\iCal\Property;
class Attendees extends Property
{
/** @var Property[] */
protected $attendees = array();
protected $attendees = [];
const PROPERTY_NAME = 'ATTENDEES';
......@@ -31,7 +31,7 @@ class Attendees extends Property
*
* @return $this
*/
public function add($value, $params = array())
public function add($value, $params = [])
{
$this->attendees[] = new Property('ATTENDEE', $value, $params);
......@@ -63,7 +63,7 @@ class Attendees extends Property
*/
public function toLines()
{
$lines = array();
$lines = [];
foreach ($this->attendees as $attendee) {
$lines[] = $attendee->toLine();
}
......
......@@ -24,7 +24,7 @@ class Organizer extends Property
* @param string $value
* @param array $params
*/
public function __construct($value, $params = array())
public function __construct($value, $params = [])
{
parent::__construct(self::PROPERTY_NAME, $value, $params);
}
......
......@@ -13,8 +13,8 @@ namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\ParameterBag;
use Eluceo\iCal\Property;
use Eluceo\iCal\Util\DateUtil;
use Eluceo\iCal\Property\ValueInterface;
use Eluceo\iCal\Util\DateUtil;
/**
* Implementation of Recurrence Id.
......@@ -29,7 +29,7 @@ class RecurrenceId extends Property
* The effective range of recurrence instances from the instance
* specified by the recurrence identifier specified by the property.
*/
const RANGE_THISANDPRIOR = 'THISANDPRIOR';
const RANGE_THISANDPRIOR = 'THISANDPRIOR';
const RANGE_THISANDFUTURE = 'THISANDFUTURE';
/**
......
......@@ -11,8 +11,8 @@
namespace Eluceo\iCal\Property\Event;
use Eluceo\iCal\Property\ValueInterface;
use Eluceo\iCal\ParameterBag;
use Eluceo\iCal\Property\ValueInterface;
use InvalidArgumentException;
/**
......@@ -22,21 +22,21 @@ use InvalidArgumentException;
*/
class RecurrenceRule implements ValueInterface
{
const FREQ_YEARLY = 'YEARLY';
const FREQ_MONTHLY = 'MONTHLY';
const FREQ_WEEKLY = 'WEEKLY';
const FREQ_DAILY = 'DAILY';
const FREQ_HOURLY = 'HOURLY';
const FREQ_YEARLY = 'YEARLY';
const FREQ_MONTHLY = 'MONTHLY';
const FREQ_WEEKLY = 'WEEKLY';
const FREQ_DAILY = 'DAILY';
const FREQ_HOURLY = 'HOURLY';
const FREQ_MINUTELY = 'MINUTELY';
const FREQ_SECONDLY = 'SECONDLY';
const WEEKDAY_SUNDAY = 'SU';
const WEEKDAY_MONDAY = 'MO';
const WEEKDAY_TUESDAY = 'TU';
const WEEKDAY_SUNDAY = 'SU';
const WEEKDAY_MONDAY = 'MO';
const WEEKDAY_TUESDAY = 'TU';
const WEEKDAY_WEDNESDAY = 'WE';
const WEEKDAY_THURSDAY = 'TH';
const WEEKDAY_FRIDAY = 'FR';
const WEEKDAY_SATURDAY = 'SA';
const WEEKDAY_THURSDAY = 'TH';
const WEEKDAY_FRIDAY = 'FR';
const WEEKDAY_SATURDAY = 'SA';
/**
* The frequency of an Event.
......
......@@ -16,7 +16,7 @@ class PropertyBag implements \IteratorAggregate
/**
* @var array
*/
protected $elements = array();
protected $elements = [];
/**
* Creates a new Property with $name, $value and $params.
......@@ -27,9 +27,9 @@ class PropertyBag implements \IteratorAggregate
*
* @return $this
*/
public function set($name, $value, $params = array())
public function set($name, $value, $params = [])
{
$property = new Property($name, $value, $params);
$property = new Property($name, $value, $params);
$this->elements[] = $property;
return $this;
......
......@@ -18,7 +18,7 @@ class ComponentUtil
*
* According to RFC 2445, all lines longer than 75 characters will be folded
*
* @link http://www.ietf.org/rfc/rfc2445.txt
* @see http://www.ietf.org/rfc/rfc2445.txt
*
* @param $string
*
......@@ -26,10 +26,10 @@ class ComponentUtil
*/
public static function fold($string)
{
$lines = array();
$lines = [];
$array = preg_split('/(?<!^)(?!$)/u', $string);
$line = '';
$line = '';
$lineNo = 0;
foreach ($array as $char) {
$charLen = strlen($char);
......
......@@ -15,10 +15,10 @@ class DateUtil
{
public static function getDefaultParams(\DateTime $dateTime = null, $noTime = false, $useTimezone = false)
{
$params = array();
$params = [];
if ($useTimezone && $noTime === false) {
$timeZone = $dateTime->getTimezone()->getName();
$timeZone = $dateTime->getTimezone()->getName();
$params['TZID'] = $timeZone;
}
......
......@@ -27,13 +27,13 @@ class PropertyValueUtil
$value = str_replace('"', '\\"', $value);
$value = str_replace(',', '\\,', $value);
$value = str_replace(';', '\\;', $value);
$value = str_replace(array(
$value = str_replace([
"\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07",
"\x08", "\x09", /* \n*/ "\x0B", "\x0C", "\x0D", "\x0E", "\x0F",
"\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17",
"\x18", "\x19", "\x1A", "\x1B", "\x1C", "\x1D", "\x1E", "\x1F",
"\x7F",
), '', $value);
], '', $value);
return $value;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment