cs: Fix code style (safe rules only).

This commit is contained in:
Pol Dellaiera
2021-11-23 14:06:38 +01:00
parent 149d7ce991
commit 8f96a1121d
1223 changed files with 65199 additions and 64625 deletions

View File

@@ -1,47 +1,45 @@
<?php
/*
/**
* Chill is a software for social workers
*
* Copyright (C) 2014, Champs Libres Cooperative SCRLFS, <http://www.champs-libres.coop>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace Chill\EventBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use ArrayAccess;
use Chill\MainBundle\Entity\Center;
use Chill\MainBundle\Entity\HasCenterInterface;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\Scope;
use Chill\PersonBundle\Entity\Person;
use Chill\MainBundle\Entity\HasScopeInterface;
use Chill\MainBundle\Entity\HasCenterInterface;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use RuntimeException;
use Symfony\Component\Validator\Context\ExecutionContextInterface;
/**
* Class Participation
* Class Participation.
*
* @package Chill\EventBundle\Entity
* @ORM\Entity(
* repositoryClass="Chill\EventBundle\Repository\ParticipationRepository")
* repositoryClass="Chill\EventBundle\Repository\ParticipationRepository")
* @ORM\Table(name="chill_event_participation")
* @ORM\HasLifecycleCallbacks()
* @ORM\HasLifecycleCallbacks
*/
class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAccess
class Participation implements HasCenterInterface, HasScopeInterface, ArrayAccess
{
/**
* @var integer
* @var Event
* @ORM\ManyToOne(
* targetEntity="Chill\EventBundle\Entity\Event",
* inversedBy="participations")
*/
private $event;
/**
* @var int
*
* @ORM\Id
* @ORM\Column(name="id", type="integer")
@@ -50,18 +48,10 @@ class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAcce
private $id;
/**
* @var \DateTime
* @var DateTime
* @ORM\Column(type="datetime")
*/
private $lastUpdate;
/**
* @var Event
* @ORM\ManyToOne(
* targetEntity="Chill\EventBundle\Entity\Event",
* inversedBy="participations")
*/
private $event;
/**
* @var Person
@@ -81,60 +71,21 @@ class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAcce
*/
private $status;
/**
* Get id
*
* @return integer
* @return Center
*/
public function getId()
public function getCenter()
{
return $this->id;
}
/**
* Set lastUpdate
*
* @param \DateTime $lastUpdate
* @return Participation
*/
protected function update()
{
$this->lastUpdate = new \DateTime('now');
return $this;
}
/**
* Get lastUpdate
*
* @return \DateTime
*/
public function getLastUpdate()
{
return $this->lastUpdate;
}
/**
* Set event
*
* @param Event $event
* @return Participation
*/
public function setEvent(Event $event = null)
{
if ($this->event !== $event) {
$this->update();
if ($this->getEvent() === null) {
throw new RuntimeException('The event is not linked with this instance. '
. 'You should initialize the event with a valid center before.');
}
$this->event = $event;
return $this;
return $this->getEvent()->getCenter();
}
/**
* Get event
* Get event.
*
* @return Event
*/
@@ -144,24 +95,27 @@ class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAcce
}
/**
* Set person
* Get id.
*
* @param Person $person
* @return Participation
* @return int
*/
public function setPerson(Person $person = null)
public function getId()
{
if ($person !== $this->person) {
$this->update();
}
$this->person = $person;
return $this;
return $this->id;
}
/**
* Get person
* Get lastUpdate.
*
* @return DateTime
*/
public function getLastUpdate()
{
return $this->lastUpdate;
}
/**
* Get person.
*
* @return Person
*/
@@ -171,12 +125,190 @@ class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAcce
}
/**
* Set role
* Get role.
*
* @return Role
*/
public function getRole()
{
return $this->role;
}
/**
* @return Scope
*/
public function getScope()
{
if ($this->getEvent() === null) {
throw new RuntimeException('The event is not linked with this instance. '
. 'You should initialize the event with a valid center before.');
}
return $this->getEvent()->getCircle();
}
/**
* Get status.
*
* @return Status
*/
public function getStatus()
{
return $this->status;
}
/**
* Check that :.
*
* - the role can be associated with this event type
* - the status can be associated with this event type
*/
public function isConsistent(ExecutionContextInterface $context)
{
if ($this->getEvent() === null || $this->getRole() === null || $this->getStatus() === null) {
return;
}
if ($this->getRole()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The role is not allowed with this event type')
->atPath('role')
->addViolation();
}
if ($this->getStatus()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The status is not allowed with this event type')
->atPath('status')
->addViolation();
}
}
/**
* @param mixed $offset
*
* @return bool
*/
public function offsetExists($offset)
{
return in_array($offset, [
'person', 'role', 'status', 'event',
]);
}
/**
* @param mixed $offset
*
* @return Event|mixed|Person|Role|Status
*/
public function offsetGet($offset)
{
switch ($offset) {
case 'person':
return $this->getPerson();
break;
case 'role':
return $this->getRole();
break;
case 'status':
return $this->getStatus();
break;
case 'event':
return $this->getEvent();
break;
}
}
/**
* @param mixed $offset
* @param mixed $value
*
* @return Participation|void
*/
public function offsetSet($offset, $value)
{
switch ($offset) {
case 'person':
return $this->setPerson($value);
break;
case 'role':
return $this->setRole($value);
break;
case 'status':
return $this->setStatus($value);
break;
case 'event':
return $this->setEvent($value);
break;
}
}
/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
$this->offsetSet($offset, null);
}
/**
* Set event.
*
* @param Event $event
*
* @param Role $role
* @return Participation
*/
public function setRole(Role $role = null)
public function setEvent(?Event $event = null)
{
if ($this->event !== $event) {
$this->update();
}
$this->event = $event;
return $this;
}
/**
* Set person.
*
* @param Person $person
*
* @return Participation
*/
public function setPerson(?Person $person = null)
{
if ($person !== $this->person) {
$this->update();
}
$this->person = $person;
return $this;
}
/**
* Set role.
*
* @param Role $role
*
* @return Participation
*/
public function setRole(?Role $role = null)
{
if ($role !== $this->role) {
$this->update();
@@ -187,160 +319,32 @@ class Participation implements HasCenterInterface, HasScopeInterface, \ArrayAcce
}
/**
* Get role
*
* @return Role
*/
public function getRole()
{
return $this->role;
}
/**
* Set status
* Set status.
*
* @param Status $status
*
* @return Participation
*/
public function setStatus(Status $status = null)
public function setStatus(?Status $status = null)
{
if ($this->status !== $status) {
$this->update();
}
$this->status = $status;
return $this;
}
/**
* Get status
* Set lastUpdate.
*
* @return Status
* @return Participation
*/
public function getStatus()
protected function update()
{
return $this->status;
}
/**
* @return Center
*/
public function getCenter()
{
if ($this->getEvent() === NULL) {
throw new \RuntimeException('The event is not linked with this instance. '
. 'You should initialize the event with a valid center before.');
}
return $this->getEvent()->getCenter();
}
/**
* @return Scope
*/
public function getScope()
{
if ($this->getEvent() === NULL) {
throw new \RuntimeException('The event is not linked with this instance. '
. 'You should initialize the event with a valid center before.');
}
return $this->getEvent()->getCircle();
}
/**
* Check that :
*
* - the role can be associated with this event type
* - the status can be associated with this event type
*
* @param ExecutionContextInterface $context
*/
public function isConsistent(ExecutionContextInterface $context)
{
if ($this->getEvent() === NULL || $this->getRole() === NULL || $this->getStatus() === NULL) {
return;
}
if ($this->getRole()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The role is not allowed with this event type')
->atPath('role')
->addViolation();
}
if ($this->getStatus()->getType()->getId() !==
$this->getEvent()->getType()->getId()) {
$context->buildViolation('The status is not allowed with this event type')
->atPath('status')
->addViolation();
}
}
/**
* @param mixed $offset
* @return bool
*/
public function offsetExists($offset)
{
return in_array($offset, array(
'person', 'role', 'status', 'event'
));
}
/**
* @param mixed $offset
* @return Event|Role|Status|Person|mixed
*/
public function offsetGet($offset)
{
switch ($offset) {
case 'person':
return $this->getPerson();
break;
case 'role':
return $this->getRole();
break;
case 'status':
return $this->getStatus();
break;
case 'event':
return $this->getEvent();
break;
}
}
/**
* @param mixed $offset
* @param mixed $value
* @return Participation|void
*/
public function offsetSet($offset, $value)
{
switch($offset) {
case 'person':
return $this->setPerson($value);
break;
case 'role':
return $this->setRole($value);
break;
case 'status':
return $this->setStatus($value);
break;
case 'event':
return $this->setEvent($value);
break;
}
}
/**
* @param mixed $offset
*/
public function offsetUnset($offset)
{
$this->offsetSet($offset, null);
}
$this->lastUpdate = new DateTime('now');
return $this;
}
}