Skip to content

Commit

Permalink
Merge pull request #5 from elchristo/feature/add-phpstan
Browse files Browse the repository at this point in the history
[feature] Add phpstan and fix errors
  • Loading branch information
elchristo authored Oct 21, 2018
2 parents e0382cb + 387deb5 commit b46660a
Show file tree
Hide file tree
Showing 21 changed files with 139 additions and 68 deletions.
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Composer files
composer.phar
vendor/
/phpstan.neon

# Generated files
.DS_Store
Expand All @@ -21,4 +22,9 @@ tests/_support/_generated/*
.settings/
nbproject
*.sublime-project
*.sublime-workspace
*.sublime-workspace
.vscode
.docker
.dockerignore
docker-*.yml
Dockerfile
20 changes: 15 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,25 @@ language: php
php:
- '7.0'
- '7.1'
- '7.2'
sudo: false
env:
RUN_PHPSTAN=false
matrix:
include:
- php: '7.1'
env: RUN_PHPSTAN=true
- php: '7.2'
env: RUN_PHPSTAN=true
cache:
directories:
- vendor
- $HOME/.composer/cache
install:
- composer self-update && composer --version
- composer install --no-interaction
branches:
only: master
cache:
directories:
- vendor
- $HOME/.composer/cache
script:
- php vendor/bin/codecept run cli,unit # self tests
- php vendor/bin/codecept run cli,unit
- if [ $RUN_PHPSTAN = "true" ]; then php vendor/bin/phpstan analyze ./; fi
9 changes: 8 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
# Changelog

## 2.0
## 2.1.0

- Add phpstan and fix errors
- Improve travis CI and add PHP 7.2
- Small code improvements and documentation


## 2.0.0

- new stable release compatible PHP 7.1 (drop PHP 5.6 support)
- replace internal service container by Zend Framework service manager component (#1)
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
"require-dev": {
"fzaninotto/faker": "^1.6",
"phpunit/phpunit": "^6.3",
"codeception/codeception": "^2.3"
"codeception/codeception": "^2.3",
"phpstan/phpstan": "~0.9"
},
"license": "MIT"
}
12 changes: 12 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
parameters:
level: 7
fileExtensions:
- php
excludes_analyse:
- %currentWorkingDirectory%/tests/*
- %currentWorkingDirectory%/vendor/*
ignoreErrors:
- '#$subject of function str_replace expects array|string, string|false given.#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+::asArray\(\)#'
- '#Call to an undefined method [a-zA-Z0-9\\_]+ContainerInterface::build\(\)#'
- '#Call to an undefined method object::toList().#'
4 changes: 2 additions & 2 deletions src/Elchristo/Calendar/Converter/ConverterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ interface ConverterInterface
/**
* Method to convert events of given calendar instance
*
* @param Collection $calendar Calendar containing events to convert
* @param array $options Additional options
* @param CalendarInterface $calendar Calendar containing events to convert
* @param array $options Additional options
*/
public function convert(CalendarInterface $calendar, array $options = []);
}
10 changes: 10 additions & 0 deletions src/Elchristo/Calendar/Converter/ConvertibleEventInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,14 @@ interface ConvertibleEventInterface
* Method to convert a single calendar event into converter format
*/
public function convert();

/**
* @return array
*/
public function getOptions();

/**
* @return array
*/
public function setOptions(array $options);
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ abstract class AbstractFullCalendarEvent implements ConvertibleEventInterface
protected $title;

/** @var string title details to show on hover */
protected $titleDetails = null;
protected $titleDetails;

/** @var string event description */
protected $description;
Expand Down Expand Up @@ -59,7 +59,7 @@ public function asArray()
'id' => $this->event->getUid(),
'idBySource' => $this->event->getId(),
'title' => $this->title,
'titleDetails' => \is_null($this->titleDetails) ? $this->description : $this->titleDetails,
'titleDetails' => null === $this->titleDetails ? $this->description : $this->titleDetails,
'description' => $this->description,
'published' => $this->event->isPublic(),
'type' => $this->event->getType(),
Expand Down Expand Up @@ -100,7 +100,7 @@ private function convertDatetimeForFullCalendar(DateTime $dt)
* @param string $name method name
* @param array $arguments arguments
*
* @return self
* @return self|null
*/
public function __call($name, $arguments)
{
Expand Down Expand Up @@ -146,16 +146,14 @@ protected function mergeAttributes($event = [])
/**
* Find attribut by value
*
* @param mixed array|string|object $attributes single or multiple attributes
* @param string $value value
* @param array|string|object $attributes single or multiple attributes
* @param string $value value
* @return string
*/
private function findAttributeValue($attributes, $value = null)
{
// Construire tableau avec les éléments
$aElements = (\is_array($attributes)) ? $attributes : [$attributes];

// Parcourir les éléments
foreach ($aElements as $elem) {
if (\is_array($elem)) {
$value .= $this->findAttributeValue($elem, $value);
Expand All @@ -182,7 +180,7 @@ private function findAttributeValue($attributes, $value = null)
$value = $elem;
} elseif (\is_object($elem)) {
if (\in_array(Collection::class, \class_implements($elem))) {
$value = $elem->toList(['title']);
$value = $elem->toList('title');
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ abstract class AbstractIcalEvent implements ConvertibleEventInterface

/**
*
* @param Event $event Calendar event to convert
* @param CalendarEventInterface $event Calendar event to convert
*/
public function __construct(CalendarEventInterface $event)
{
$this->event = $event;
$tsNow = \DateTime::createFromFormat(self::DTSTAMP_FORMAT, time());
$tsNow = (string) \time();
$this->timestamp = $tsNow;
$this->created = $tsNow;
$this->lastModified = $tsNow;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(CalendarEventInterface $event)
* Set additional options
*
* @param array $options
* @return AbstractVEvent
* @return self
*
*/
public function setOptions(array $options = [])
Expand Down
7 changes: 3 additions & 4 deletions src/Elchristo/Calendar/Model/AbstractCalendar.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,16 @@
namespace Elchristo\Calendar\Model;

use Elchristo\Calendar\Exception\RuntimeException;
use Elchristo\Calendar\Model\AbstractSource;
use Elchristo\Calendar\Model\Source\SourceInterface;
use Elchristo\Calendar\Service\Builder\SourceBuilder;
use Elchristo\Calendar\Model\Event\Collection as EventsCollection;
use Elchristo\Calendar\Model\CalendarInterface;
use Elchristo\Calendar\Service\Config\ConfigAwareInterface;
use Elchristo\Calendar\Service\Config\ConfigProviderTrait;

/**
* Default abstract calendar class
*/
abstract class AbstractCalendar implements CalendarInterface, ConfigAwareInterface
abstract class AbstractCalendar implements CalendarInterface
{
use ConfigProviderTrait;

Expand Down Expand Up @@ -76,7 +75,7 @@ final public function getSourceList()
* Returns a source of the calendar if existing
*
* @param string $sourceName Requested source name
* @return AbstractSource
* @return SourceInterface
* @throws RuntimeException
*/
final public function getSource(string $sourceName)
Expand Down
3 changes: 2 additions & 1 deletion src/Elchristo/Calendar/Model/CalendarInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

namespace Elchristo\Calendar\Model;

use Elchristo\Calendar\Service\Config\ConfigAwareInterface;
use Elchristo\Calendar\Model\Event\Collection as EventsCollection;

/**
* Interface to define calendars
*/
interface CalendarInterface
interface CalendarInterface extends ConfigAwareInterface
{
/**
* Return the calendar name
Expand Down
56 changes: 28 additions & 28 deletions src/Elchristo/Calendar/Model/Event/AbstractCalendarEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ abstract class AbstractCalendarEvent implements CalendarEventInterface
const DEFAULT_IS_ALLDAY_EVENT = false;
const DEFAULT_IS_PUBLIC_EVENT = true;

/** @var integer Unique event identifier (prefixed event id) */
/** @var int|string Unique event identifier (prefixed event id) */
protected $uid;

/** @var integer Event identifier */
/** @var int|string Event identifier */
protected $id;

/** @var string */
Expand All @@ -40,10 +40,10 @@ abstract class AbstractCalendarEvent implements CalendarEventInterface
/** @var DateTime */
protected $lastModified;

/** @var boolean */
/** @var bool */
protected $alldayEvent;

/** @var boolean */
/** @var bool */
protected $public;

/** @var string */
Expand All @@ -55,9 +55,9 @@ abstract class AbstractCalendarEvent implements CalendarEventInterface
/**
* Initialize event
*
* @param string $id Event identifier
* @param array $values Event attribute values (name => value pairs)
* @param array $options Additional options passed to the event
* @param int|string $id Event identifier
* @param array $values Event attribute values (name => value pairs)
* @param array $options Additional options passed to the event
*/
public function __construct($id, array $values = [], array $options = [])
{
Expand Down Expand Up @@ -174,7 +174,8 @@ private function buildDateTime($hour = null, $minute = null)

/**
* Return unique event identifier
* @return mixed integer|string
*
* @return int|string
*/
public function getId()
{
Expand All @@ -183,7 +184,7 @@ public function getId()

/**
* Return event identifier (only unique by source)
* @return integer
* @return int|string
*/
public function getUid()
{
Expand Down Expand Up @@ -264,7 +265,7 @@ public function getStart()

/**
*
* @return DateTime
* @return self
*/
public function setStart(DateTime $dt)
{
Expand All @@ -283,7 +284,7 @@ public function getEnd()

/**
*
* @return DateTime
* @return self
*/
public function setEnd(DateTime $dt)
{
Expand Down Expand Up @@ -333,48 +334,47 @@ public function setLastModificationDate(DateTime $dt)

/**
*
* @return boolean
* @return bool
*/
public function isAlldayEvent()
public function isAlldayEvent() : bool
{
return (bool) $this->alldayEvent;
return $this->alldayEvent;
}

/**
*
* @param boolean $status
* @param bool $allday
* @return self
*/
public function setAlldayEvent($status = self::DEFAULT_IS_ALLDAY_EVENT)
public function setAlldayEvent(bool $allday = self::DEFAULT_IS_ALLDAY_EVENT)
{
if (\is_bool($status) || $status === 'true' || $status === 'false') {
$this->alldayEvent = (bool) $status;
if ((bool) $status === true) {
$this->setHourFrom($this->buildDateTime(0, 0))
->setHourTo($this->buildDateTime(23, 59));
}
$this->alldayEvent = $allday;

if ($allday === true) {
$this->start->setTime(0, 0, 0);
$this->end->setTime(23, 59, 59);
}

return $this;
}

/**
*
* @return boolean
* @return bool
*/
public function isPublic()
public function isPublic() : bool
{
return (bool) $this->public;
return $this->public;
}

/**
*
* @param boolean $status
* @param bool $status
* @return self
*/
public function setPublic($status = self::DEFAULT_IS_PUBLIC_EVENT)
public function setPublic(bool $status = self::DEFAULT_IS_PUBLIC_EVENT)
{
$this->public = (bool) $status;
$this->public = $status;
return $this;
}

Expand Down
Loading

0 comments on commit b46660a

Please sign in to comment.