diff --git a/Broadcaster/AbstractSchedulerCommands.php b/Broadcaster/AbstractSchedulerCommands.php index 4154232..dcec2d9 100644 --- a/Broadcaster/AbstractSchedulerCommands.php +++ b/Broadcaster/AbstractSchedulerCommands.php @@ -25,24 +25,24 @@ abstract class AbstractSchedulerCommands implements SchedulerCommandsInterface * * @var string|null */ - protected $kernelEnvironment; + protected ?string $kernelEnvironment; /** * Directory to store FFMpeg logs * * @var string */ - protected $logDirectoryFFMpeg = ''; + protected string $logDirectoryFFMpeg = ''; /** * @var bool Can the input be looped */ - protected $looping = false; + protected bool $looping = false; /** * @var string */ - protected $rootDir; + protected string $rootDir; /** * SchedulerCommands constructor. @@ -60,7 +60,7 @@ public function __construct(Kernel $kernel) * * @throws \Exception */ - public function startProcess($input, $output, $metadata): string + public function startProcess(string $input, string $output, array $metadata): string { $meta = ''; $metadata['env'] = $this->getKernelEnvironment(); @@ -76,7 +76,7 @@ public function startProcess($input, $output, $metadata): string * {@inheritdoc} * @throws LiveBroadcastException */ - public function stopProcess($pid): string + public function stopProcess(int $pid): string { throw new LiveBroadcastException('stopProcess Cannot be called on the abstract class'); } @@ -93,7 +93,7 @@ public function getRunningProcesses(): array /** * {@inheritdoc} */ - public function getProcessId($processString): ?int + public function getProcessId(string $processString): ?int { $pid = []; preg_match('/^\s*([\d]+)/', $processString, $pid); @@ -107,7 +107,7 @@ public function getProcessId($processString): ?int /** * {@inheritdoc} */ - public function getBroadcastId($processString): ?int + public function getBroadcastId(string $processString): ?int { $value = $this->getMetadataValue($processString, self::METADATA_BROADCAST); @@ -117,7 +117,7 @@ public function getBroadcastId($processString): ?int /** * {@inheritdoc} */ - public function getChannelId($processString): ?int + public function getChannelId(string $processString): ?int { $value = $this->getMetadataValue($processString, self::METADATA_CHANNEL); @@ -127,7 +127,7 @@ public function getChannelId($processString): ?int /** * {@inheritdoc} */ - public function getEnvironment($processString): ?string + public function getEnvironment(string $processString): ?string { return $this->getMetadataValue($processString, self::METADATA_ENVIRONMENT); } @@ -143,9 +143,9 @@ public function getKernelEnvironment(): ?string /** * @param string $directory */ - public function setFFMpegLogDirectory($directory): void + public function setFFMpegLogDirectory(string $directory): void { - if (null === $directory || !is_writable($directory)) { + if (!is_writable($directory)) { return; } @@ -155,9 +155,9 @@ public function setFFMpegLogDirectory($directory): void /** * @param bool $looping */ - public function setLooping($looping): void + public function setLooping(bool $looping): void { - $this->looping = (bool) $looping; + $this->looping = $looping; } /** @@ -179,7 +179,7 @@ public function isLooping(): bool * * @throws \Exception */ - protected function execStreamCommand($input, $output, $meta): string + protected function execStreamCommand(string $input, string $output, string $meta): string { $logFile = '/dev/null'; $loop = ''; @@ -205,7 +205,7 @@ protected function execStreamCommand($input, $output, $meta): string * * @return array */ - protected function readMetadata($processString): array + protected function readMetadata(string $processString): array { $metadata = []; $processMetadata = []; @@ -227,7 +227,7 @@ protected function readMetadata($processString): array * * @return mixed */ - private function getMetadataValue($processString, $metadataKey) + private function getMetadataValue(string $processString, string $metadataKey) { $metadata = $this->readMetadata($processString); diff --git a/Broadcaster/Linux/SchedulerCommands.php b/Broadcaster/Linux/SchedulerCommands.php index bc683d3..20fdc08 100644 --- a/Broadcaster/Linux/SchedulerCommands.php +++ b/Broadcaster/Linux/SchedulerCommands.php @@ -17,7 +17,7 @@ class SchedulerCommands extends AbstractSchedulerCommands /** * {@inheritdoc} */ - public function stopProcess($pid): string + public function stopProcess(int $pid): string { return exec(sprintf('kill %d', $pid)); } diff --git a/Broadcaster/RunningBroadcast.php b/Broadcaster/RunningBroadcast.php index 026d606..fc7c765 100644 --- a/Broadcaster/RunningBroadcast.php +++ b/Broadcaster/RunningBroadcast.php @@ -18,22 +18,22 @@ class RunningBroadcast /** * @var int */ - private $broadcastId; + private int $broadcastId; /** * @var int */ - private $processId; + private int $processId; /** * @var int */ - private $channelId; + private int $channelId; /** * @var string */ - private $environment; + private string $environment; /** * RunningBroadcast constructor. @@ -43,12 +43,12 @@ class RunningBroadcast * @param int $channelId * @param string $environment */ - public function __construct($broadcastId, $processId, $channelId, $environment) + public function __construct(int $broadcastId, int $processId, int $channelId, string $environment) { - $this->broadcastId = (int) $broadcastId; - $this->processId = (int) $processId; - $this->channelId = (int) $channelId; - $this->environment = (string) $environment; + $this->broadcastId = $broadcastId; + $this->processId = $processId; + $this->channelId = $channelId; + $this->environment = $environment; } /** @@ -99,7 +99,7 @@ public function isBroadcasting(LiveBroadcast $broadcast, AbstractChannel $channe * * @return bool */ - public function isValid($kernelEnvironment): bool + public function isValid(string $kernelEnvironment): bool { return ($kernelEnvironment === $this->getEnvironment()) && ($this->getProcessId() !== 0) && diff --git a/Broadcaster/Scheduler.php b/Broadcaster/Scheduler.php index 4a5c6ec..e01ba02 100644 --- a/Broadcaster/Scheduler.php +++ b/Broadcaster/Scheduler.php @@ -24,27 +24,27 @@ class Scheduler /** * @var ChannelValidatorService */ - protected $validator; + protected ChannelValidatorService $validator; /** * @var BroadcastStarter */ - protected $starter; + protected BroadcastStarter $starter; /** * @var BroadcastManager */ - protected $broadcastManager; + protected BroadcastManager $broadcastManager; /** * @var SchedulerCommandsInterface */ - protected $schedulerCommands; + protected SchedulerCommandsInterface $schedulerCommands; /** * @var LoggerInterface */ - protected $logger; + protected LoggerInterface $logger; /** * Scheduler constructor @@ -211,7 +211,7 @@ protected function getRunningBroadcasts(): array } /** - * Send end signals to channels where broadcasts ended + * Send end signals to the channels where broadcasts ended * * @throws LiveBroadcastException * @throws \Exception diff --git a/Broadcaster/SchedulerCommandsDetector.php b/Broadcaster/SchedulerCommandsDetector.php index febd52d..b8059b0 100644 --- a/Broadcaster/SchedulerCommandsDetector.php +++ b/Broadcaster/SchedulerCommandsDetector.php @@ -25,7 +25,7 @@ class SchedulerCommandsDetector * * @return SchedulerCommandsInterface */ - public static function createSchedulerCommands(Kernel $kernel, $ffmpegLogDirectory = null): SchedulerCommandsInterface + public static function createSchedulerCommands(Kernel $kernel, ?string $ffmpegLogDirectory = null): SchedulerCommandsInterface { $osCode = strtoupper(substr(PHP_OS, 0, 3)); diff --git a/Broadcaster/SchedulerCommandsInterface.php b/Broadcaster/SchedulerCommandsInterface.php index da12ef8..6d3f05c 100644 --- a/Broadcaster/SchedulerCommandsInterface.php +++ b/Broadcaster/SchedulerCommandsInterface.php @@ -19,14 +19,14 @@ interface SchedulerCommandsInterface * * @return string */ - public function startProcess($input, $output, $metadata): string; + public function startProcess(string $input, string $output, array $metadata): string; /** * @param int $pid * * @return string */ - public function stopProcess($pid): string; + public function stopProcess(int $pid): string; /** * @return array @@ -38,28 +38,28 @@ public function getRunningProcesses(): array; * * @return int|null */ - public function getProcessId($processString): ?int; + public function getProcessId(string $processString): ?int; /** * @param string $processString * * @return int|null */ - public function getBroadcastId($processString): ?int; + public function getBroadcastId(string $processString): ?int; /** * @param string $processString * * @return int|null */ - public function getChannelId($processString): ?int; + public function getChannelId(string $processString): ?int; /** * @param string $processString * * @return string|null */ - public function getEnvironment($processString): ?string; + public function getEnvironment(string $processString): ?string; /** * @return string|null @@ -69,10 +69,10 @@ public function getKernelEnvironment(): ?string; /** * @param string $directory */ - public function setFFMpegLogDirectory($directory); + public function setFFMpegLogDirectory(string $directory); /** * @param bool $looping */ - public function setLooping($looping); + public function setLooping(bool $looping); } diff --git a/Broadcaster/Windows/SchedulerCommands.php b/Broadcaster/Windows/SchedulerCommands.php index 49ada35..d72690c 100644 --- a/Broadcaster/Windows/SchedulerCommands.php +++ b/Broadcaster/Windows/SchedulerCommands.php @@ -17,7 +17,7 @@ class SchedulerCommands extends AbstractSchedulerCommands /** * {@inheritdoc} */ - public function stopProcess($pid): string + public function stopProcess(int $pid): string { return exec(sprintf('START /B TASKKILL /PID %d /T', $pid)); } @@ -41,7 +41,7 @@ public function getRunningProcesses(): array * * @return string */ - protected function execStreamCommand($input, $output, $meta): string + protected function execStreamCommand(string $input, string $output, string $meta): string { $loop = ''; diff --git a/Entity/Channel/AbstractChannel.php b/Entity/Channel/AbstractChannel.php index 6014aa0..1ea5214 100644 --- a/Entity/Channel/AbstractChannel.php +++ b/Entity/Channel/AbstractChannel.php @@ -30,7 +30,7 @@ abstract class AbstractChannel * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ - protected $channelId; + protected ?int $channelId = null; /** * @var string|null @@ -39,14 +39,14 @@ abstract class AbstractChannel * * @Assert\NotBlank */ - protected $channelName; + protected ?string $channelName = null; /** * @var bool * * @ORM\Column(name="is_healthy", type="boolean", options={"default": 0}) */ - protected $isHealthy = false; + protected bool $isHealthy = false; /** * @return int|null @@ -65,11 +65,11 @@ public function getChannelName(): ?string } /** - * @param string $channelName + * @param string|null $channelName * * @return $this */ - public function setChannelName($channelName): self + public function setChannelName(?string $channelName): self { $this->channelName = $channelName; @@ -107,7 +107,7 @@ public static function isEntityConfigured($configuration): bool return true; } - return true; + return false; } /** diff --git a/Entity/Channel/ChannelFacebook.php b/Entity/Channel/ChannelFacebook.php index 4004f7d..ea96468 100644 --- a/Entity/Channel/ChannelFacebook.php +++ b/Entity/Channel/ChannelFacebook.php @@ -25,7 +25,7 @@ class ChannelFacebook extends AbstractChannel implements PlannedChannelInterface * * @Assert\NotBlank */ - protected $accessToken; + protected ?string $accessToken = null; /** * @var string|null @@ -34,7 +34,7 @@ class ChannelFacebook extends AbstractChannel implements PlannedChannelInterface * * @Assert\NotBlank */ - protected $fbEntityId; + protected ?string $fbEntityId = null; /** * @return string|null @@ -45,11 +45,11 @@ public function getAccessToken(): ?string } /** - * @param string $accessToken + * @param string|null $accessToken * * @return ChannelFacebook */ - public function setAccessToken($accessToken): ChannelFacebook + public function setAccessToken(?string $accessToken): ChannelFacebook { $this->accessToken = $accessToken; @@ -65,11 +65,11 @@ public function getFbEntityId(): ?string } /** - * @param string $fbEntityId + * @param string|null $fbEntityId * * @return ChannelFacebook */ - public function setFbEntityId($fbEntityId): ChannelFacebook + public function setFbEntityId(?string $fbEntityId): ChannelFacebook { $this->fbEntityId = $fbEntityId; diff --git a/Entity/Channel/ChannelTwitch.php b/Entity/Channel/ChannelTwitch.php index 2044e95..61bf754 100644 --- a/Entity/Channel/ChannelTwitch.php +++ b/Entity/Channel/ChannelTwitch.php @@ -25,7 +25,7 @@ class ChannelTwitch extends AbstractChannel * * @Assert\NotBlank */ - protected $streamKey; + protected ?string $streamKey = null; /** * @var string|null @@ -34,7 +34,7 @@ class ChannelTwitch extends AbstractChannel * * @Assert\NotBlank */ - protected $streamServer = 'live.twitch.tv'; + protected ?string $streamServer = 'live.twitch.tv'; /** * @return string|null @@ -45,11 +45,11 @@ public function getStreamKey(): ?string } /** - * @param string $streamKey + * @param string|null $streamKey * * @return ChannelTwitch */ - public function setStreamKey($streamKey): ChannelTwitch + public function setStreamKey(?string $streamKey): ChannelTwitch { $this->streamKey = $streamKey; @@ -65,11 +65,11 @@ public function getStreamServer(): ?string } /** - * @param string $streamServer + * @param string|null $streamServer * * @return ChannelTwitch */ - public function setStreamServer($streamServer): ChannelTwitch + public function setStreamServer(?string $streamServer): ChannelTwitch { $this->streamServer = $streamServer; diff --git a/Entity/Channel/ChannelYouTube.php b/Entity/Channel/ChannelYouTube.php index 18eb7f6..5de0d83 100644 --- a/Entity/Channel/ChannelYouTube.php +++ b/Entity/Channel/ChannelYouTube.php @@ -25,7 +25,7 @@ class ChannelYouTube extends AbstractChannel implements PlannedChannelInterface * * @Assert\NotBlank */ - protected $refreshToken; + protected ?string $refreshToken; /** * @var string|null @@ -34,7 +34,7 @@ class ChannelYouTube extends AbstractChannel implements PlannedChannelInterface * * @Assert\NotBlank */ - protected $youTubeChannelName; + protected ?string $youTubeChannelName; /** * @return string|null @@ -45,11 +45,11 @@ public function getRefreshToken(): ?string } /** - * @param string $refreshToken + * @param string|null $refreshToken * * @return ChannelYouTube */ - public function setRefreshToken($refreshToken): ChannelYouTube + public function setRefreshToken(?string $refreshToken): ChannelYouTube { $this->refreshToken = $refreshToken; @@ -65,11 +65,11 @@ public function getYouTubeChannelName(): ?string } /** - * @param string $youTubeChannelName + * @param string|null $youTubeChannelName * * @return ChannelYouTube */ - public function setYouTubeChannelName($youTubeChannelName): ChannelYouTube + public function setYouTubeChannelName(?string $youTubeChannelName): ChannelYouTube { $this->youTubeChannelName = $youTubeChannelName; diff --git a/Entity/Channel/PlannedChannelInterface.php b/Entity/Channel/PlannedChannelInterface.php index acc8f9f..fab3871 100644 --- a/Entity/Channel/PlannedChannelInterface.php +++ b/Entity/Channel/PlannedChannelInterface.php @@ -12,5 +12,4 @@ */ interface PlannedChannelInterface { - } diff --git a/Entity/LiveBroadcast.php b/Entity/LiveBroadcast.php index c4925d6..02e98f8 100644 --- a/Entity/LiveBroadcast.php +++ b/Entity/LiveBroadcast.php @@ -34,7 +34,7 @@ class LiveBroadcast * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ - private $broadcastId; + private ?int $broadcastId = null; /** * @var string|null @@ -43,14 +43,14 @@ class LiveBroadcast * * @Assert\NotBlank */ - private $name; + private ?string $name = null; /** * @var string|null * * @ORM\Column(name="description", type="text", length=65535, nullable=true) */ - private $description; + private ?string $description = null; /** * @var UploadedFile|File|null @@ -67,7 +67,7 @@ class LiveBroadcast * @ORM\ManyToOne(targetEntity="Martin1982\LiveBroadcastBundle\Entity\Media\AbstractMedia") * @ORM\JoinColumn(name="input_id", referencedColumnName="id") */ - private $input; + private ?AbstractMedia $input; /** * @var \DateTime @@ -76,7 +76,7 @@ class LiveBroadcast * * @Assert\GreaterThan("+30 seconds") */ - private $startTimestamp; + private \DateTime $startTimestamp; /** * @var \DateTime @@ -85,21 +85,21 @@ class LiveBroadcast * * @Assert\GreaterThan("+1 minute") */ - private $endTimestamp; + private \DateTime $endTimestamp; /** * @var int * * @ORM\Column(name="privacy_status", type="integer", options={"default": 0}) */ - private $privacyStatus = self::PRIVACY_STATUS_PUBLIC; + private int $privacyStatus = self::PRIVACY_STATUS_PUBLIC; /** * @var bool * * @ORM\Column(name="stop_on_end_timestamp", type="boolean", nullable=false) */ - private $stopOnEndTimestamp = true; + private bool $stopOnEndTimestamp = true; /** * @var AbstractChannel[] @@ -149,11 +149,11 @@ public function getName(): ?string } /** - * @param string $name + * @param string|null $name * * @return LiveBroadcast */ - public function setName($name): LiveBroadcast + public function setName(?string $name): LiveBroadcast { $this->name = $name; @@ -169,11 +169,11 @@ public function getDescription(): ?string } /** - * @param string $description + * @param string|null $description * * @return LiveBroadcast */ - public function setDescription($description): LiveBroadcast + public function setDescription(?string $description): LiveBroadcast { $this->description = $description; @@ -213,7 +213,7 @@ public function getStartTimestamp(): \DateTime * * @return LiveBroadcast */ - public function setStartTimestamp($startTimestamp): LiveBroadcast + public function setStartTimestamp(\DateTime $startTimestamp): LiveBroadcast { $this->startTimestamp = $startTimestamp; @@ -233,7 +233,7 @@ public function getEndTimestamp(): \DateTime * * @return LiveBroadcast */ - public function setEndTimestamp($endTimestamp): LiveBroadcast + public function setEndTimestamp(\DateTime $endTimestamp): LiveBroadcast { $this->endTimestamp = $endTimestamp; @@ -245,7 +245,7 @@ public function setEndTimestamp($endTimestamp): LiveBroadcast * * @return LiveBroadcast */ - public function setOutputChannels($channels): self + public function setOutputChannels(array $channels = []): self { if (count($channels) > 0) { foreach ($channels as $channel) { @@ -321,7 +321,7 @@ public function isStopOnEndTimestamp(): bool * * @return LiveBroadcast */ - public function setStopOnEndTimestamp($stopOnEndTimestamp): LiveBroadcast + public function setStopOnEndTimestamp(bool $stopOnEndTimestamp): LiveBroadcast { $this->stopOnEndTimestamp = $stopOnEndTimestamp; diff --git a/Entity/Media/AbstractMedia.php b/Entity/Media/AbstractMedia.php index 36331ea..dcc4d9f 100644 --- a/Entity/Media/AbstractMedia.php +++ b/Entity/Media/AbstractMedia.php @@ -26,7 +26,7 @@ abstract class AbstractMedia * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ - protected $inputId; + protected ?int $inputId = null; /** * @return int|null diff --git a/Entity/Media/MediaFile.php b/Entity/Media/MediaFile.php index 75f9653..4f3c9d0 100644 --- a/Entity/Media/MediaFile.php +++ b/Entity/Media/MediaFile.php @@ -25,7 +25,7 @@ class MediaFile extends AbstractMedia * * @Assert\File() */ - protected $fileLocation; + protected ?string $fileLocation = null; /** * @return string|null @@ -36,11 +36,11 @@ public function getFileLocation(): ?string } /** - * @param string $fileLocation + * @param string|null $fileLocation * * @return MediaFile */ - public function setFileLocation($fileLocation): MediaFile + public function setFileLocation(?string $fileLocation): MediaFile { $this->fileLocation = $fileLocation; diff --git a/Entity/Media/MediaRtmp.php b/Entity/Media/MediaRtmp.php index 5105345..59a3897 100644 --- a/Entity/Media/MediaRtmp.php +++ b/Entity/Media/MediaRtmp.php @@ -25,7 +25,7 @@ class MediaRtmp extends AbstractMedia * * @Assert\Url() */ - protected $rtmpAddress; + protected ?string $rtmpAddress = null; /** * @return string|null @@ -36,11 +36,11 @@ public function getRtmpAddress(): ?string } /** - * @param string $rtmpAddress + * @param string|null $rtmpAddress * * @return MediaRtmp */ - public function setRtmpAddress($rtmpAddress): MediaRtmp + public function setRtmpAddress(?string $rtmpAddress): MediaRtmp { $this->rtmpAddress = str_replace('rtmp://', '', $rtmpAddress); diff --git a/Entity/Media/MediaUrl.php b/Entity/Media/MediaUrl.php index 2287467..473b0be 100644 --- a/Entity/Media/MediaUrl.php +++ b/Entity/Media/MediaUrl.php @@ -26,7 +26,7 @@ class MediaUrl extends AbstractMedia * * @ORM\Column(name="url", type="string", nullable=false) */ - protected $url; + protected ?string $url = null; /** * @return string|null @@ -37,11 +37,11 @@ public function getUrl(): ?string } /** - * @param string $url + * @param string|null $url * * @return MediaUrl */ - public function setUrl($url): MediaUrl + public function setUrl(?string $url): MediaUrl { $this->url = $url; diff --git a/Entity/Metadata/StreamEvent.php b/Entity/Metadata/StreamEvent.php index fa67016..3bf07f9 100644 --- a/Entity/Metadata/StreamEvent.php +++ b/Entity/Metadata/StreamEvent.php @@ -26,7 +26,7 @@ class StreamEvent * @ORM\Id * @ORM\GeneratedValue(strategy="IDENTITY") */ - private $eventId; + private ?int $eventId = null; /** * @var LiveBroadcast|null @@ -34,7 +34,7 @@ class StreamEvent * @ORM\ManyToOne(targetEntity="Martin1982\LiveBroadcastBundle\Entity\LiveBroadcast") * @ORM\JoinColumn(name="broadcast_id", referencedColumnName="id", unique=false, onDelete="CASCADE") */ - protected $broadcast; + protected ?LiveBroadcast $broadcast; /** * @var AbstractChannel|null @@ -42,21 +42,21 @@ class StreamEvent * @ORM\ManyToOne(targetEntity="Martin1982\LiveBroadcastBundle\Entity\Channel\AbstractChannel") * @ORM\JoinColumn(name="channel_id", referencedColumnName="id", unique=false, onDelete="CASCADE") */ - protected $channel; + protected ?AbstractChannel $channel; /** * @var string|null * * @ORM\Column(name="external_stream_id", type="string", length=128, nullable=false) */ - protected $externalStreamId; + protected ?string $externalStreamId = null; /** * @var bool * * @ORM\Column(name="end_signal_sent", type="boolean", nullable=true) */ - protected $endSignalSent = false; + protected bool $endSignalSent = false; /** * @return int|null @@ -115,11 +115,11 @@ public function getExternalStreamId(): ?string } /** - * @param string $externalStreamId + * @param string|null $externalStreamId * * @return StreamEvent */ - public function setExternalStreamId($externalStreamId): StreamEvent + public function setExternalStreamId(?string $externalStreamId): StreamEvent { $this->externalStreamId = $externalStreamId; diff --git a/EventListener/StreamAnnouncementListener.php b/EventListener/StreamAnnouncementListener.php index 3c6ae22..72da864 100644 --- a/EventListener/StreamAnnouncementListener.php +++ b/EventListener/StreamAnnouncementListener.php @@ -23,12 +23,12 @@ class StreamAnnouncementListener /** * @var BroadcastManager */ - protected $broadcastManager; + protected BroadcastManager $broadcastManager; /** * @var MessageBusInterface */ - protected $bus; + protected MessageBusInterface $bus; /** * StreamAnnouncementListener constructor. @@ -90,7 +90,7 @@ public function preRemove(LifecycleEventArgs $args): void /** * Get the live broadcast when available * - * @param \stdClass $object + * @param mixed $object * * @return LiveBroadcast|null */ diff --git a/EventListener/ThumbnailUploadListener.php b/EventListener/ThumbnailUploadListener.php index 8865db9..881d546 100644 --- a/EventListener/ThumbnailUploadListener.php +++ b/EventListener/ThumbnailUploadListener.php @@ -22,7 +22,7 @@ class ThumbnailUploadListener /** * @var ThumbnailUploadService */ - private $uploadService; + private ThumbnailUploadService $uploadService; /** * ThumbnailUploadListener constructor. @@ -68,7 +68,7 @@ public function postLoad(LifecycleEventArgs $args): void $thumbnail = (string) $entity->getThumbnail(); - if (null !== $thumbnail) { + if ('' !== $thumbnail) { $entity->setThumbnail( new File($thumbnail, false) ); diff --git a/Message/StreamServiceAnnouncement.php b/Message/StreamServiceAnnouncement.php index 6a751aa..e2719cc 100644 --- a/Message/StreamServiceAnnouncement.php +++ b/Message/StreamServiceAnnouncement.php @@ -17,17 +17,17 @@ class StreamServiceAnnouncement /** * @var int */ - private $actionType = 0; + private int $actionType = 0; /** * @var int */ - private $broadcastId = 0; + private int $broadcastId = 0; /** * @var int[] */ - private $previousChannels = []; + private array $previousChannels = []; /** * StreamServiceAnnouncement constructor. @@ -96,7 +96,7 @@ public function getPreviousChannels(): array * * @return StreamServiceAnnouncement */ - public function setPreviousChannels($previousChannels): StreamServiceAnnouncement + public function setPreviousChannels(array $previousChannels = []): StreamServiceAnnouncement { $this->previousChannels = $previousChannels; diff --git a/MessageHandler/StreamServiceAnnouncementHandler.php b/MessageHandler/StreamServiceAnnouncementHandler.php index aa13f78..ce9bf78 100644 --- a/MessageHandler/StreamServiceAnnouncementHandler.php +++ b/MessageHandler/StreamServiceAnnouncementHandler.php @@ -18,7 +18,7 @@ class StreamServiceAnnouncementHandler implements MessageHandlerInterface /** * @var BroadcastManager */ - private $manager; + private BroadcastManager $manager; /** * StreamServiceAnnouncementHandler constructor. diff --git a/README.md b/README.md index 85b3c21..c79a3b9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ The Live Broadcast Bundle will make it possible to plan live video streams to various websites/apps like Twitch, YouTube Live, Facebook Live. -You are able to stream from various inputs. This package supports files, URL's or existing RTMP streams. +You are able to stream from various inputs. This package supports files, URLs or existing RTMP streams. For more info you can view the latest recorded presentation below, check the demo project at https://github.com/Martin1982/live-broadcast-demo or read on; diff --git a/Service/BroadcastManager.php b/Service/BroadcastManager.php index af0ba1e..529f863 100644 --- a/Service/BroadcastManager.php +++ b/Service/BroadcastManager.php @@ -9,9 +9,7 @@ use Doctrine\Common\Collections\Collection; use Doctrine\ORM\EntityManager; -use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\ORMException; -use Doctrine\ORM\ORMInvalidArgumentException; +use Doctrine\ORM\Exception\ORMException; use Martin1982\LiveBroadcastBundle\Entity\Channel\AbstractChannel; use Martin1982\LiveBroadcastBundle\Entity\Channel\PlannedChannelInterface; use Martin1982\LiveBroadcastBundle\Entity\LiveBroadcast; @@ -31,12 +29,12 @@ class BroadcastManager /** * @var EntityManager */ - protected $entityManager; + protected EntityManager $entityManager; /** * @var ChannelApiStack */ - protected $apiStack; + protected ChannelApiStack $apiStack; /** * BroadcastManager constructor @@ -51,7 +49,7 @@ public function __construct(EntityManager $entityManager, ChannelApiStack $apiSt } /** - * Get a broadcast by it's id + * Get a broadcast by its id * * @param string|int $broadcastId * @@ -59,13 +57,12 @@ public function __construct(EntityManager $entityManager, ChannelApiStack $apiSt */ public function getBroadcastById($broadcastId) { - $broadcastRepository = $this->getBroadcastsRepository(); - - return $broadcastRepository->findOneBy([ 'broadcastId' => (int) $broadcastId ]); + return $this->getBroadcastsRepository() + ->findOneBy([ 'broadcastId' => (int) $broadcastId ]); } /** - * Retrieve a channel by it's id + * Retrieve a channel by its id * * @param int $id * @@ -73,9 +70,9 @@ public function getBroadcastById($broadcastId) */ public function getChannelById(int $id): ?AbstractChannel { - $repository = $this->entityManager->getRepository(AbstractChannel::class); - - return $repository->find($id); + return $this->entityManager + ->getRepository(AbstractChannel::class) + ->find($id); } /** @@ -137,17 +134,17 @@ public function preDelete(LiveBroadcast $broadcast): void } /** - * Send a end signal for a broadcast's stream + * Send an end signal for a broadcast's stream * * @param StreamEvent $event * - * @throws LiveBroadcastException + * @throws LiveBroadcastException|\Doctrine\ORM\ORMException */ public function sendEndSignal(StreamEvent $event): void { $channel = $event->getChannel(); - if ($channel && $channel instanceof PlannedChannelInterface) { + if ($channel instanceof PlannedChannelInterface) { $api = $this->apiStack->getApiForChannel($channel); if ($api) { @@ -158,10 +155,6 @@ public function sendEndSignal(StreamEvent $event): void $this->entityManager->flush(); $api->sendEndSignal($channel, $event->getExternalStreamId()); - } catch (OptimisticLockException $exception) { - throw new LiveBroadcastException(sprintf('Couldn\'t save broadcast end: %s', $exception->getMessage())); - } catch (ORMInvalidArgumentException $exception) { - throw new LiveBroadcastException(sprintf('Couldn\'t save broadcast end: %s', $exception->getMessage())); } catch (ORMException $exception) { throw new LiveBroadcastException(sprintf('Couldn\'t save broadcast end: %s', $exception->getMessage())); } diff --git a/Service/BroadcastStarter.php b/Service/BroadcastStarter.php index ceb00e2..77bd4a3 100644 --- a/Service/BroadcastStarter.php +++ b/Service/BroadcastStarter.php @@ -20,17 +20,17 @@ class BroadcastStarter /** * @var StreamInputService */ - protected $inputService; + protected StreamInputService $inputService; /** * @var StreamOutputService */ - protected $outputService; + protected StreamOutputService $outputService; /** * @var SchedulerCommandsInterface */ - protected $commands; + protected SchedulerCommandsInterface $commands; /** * BroadcastStarter constructor diff --git a/Service/ChannelApi/ChannelApiStack.php b/Service/ChannelApi/ChannelApiStack.php index 059f34f..64a866b 100644 --- a/Service/ChannelApi/ChannelApiStack.php +++ b/Service/ChannelApi/ChannelApiStack.php @@ -19,7 +19,7 @@ class ChannelApiStack /** * @var ChannelApiInterface[] */ - private $apis = []; + private array $apis = []; /** * @param ChannelApiInterface $api @@ -59,7 +59,7 @@ public function getApiForChannel(AbstractChannel $channel): ?ChannelApiInterface * * @return ChannelApiInterface|null */ - protected function findServiceObject($className): ?ChannelApiInterface + protected function findServiceObject(string $className): ?ChannelApiInterface { $serviceApi = null; diff --git a/Service/ChannelApi/Client/Config/GoogleConfig.php b/Service/ChannelApi/Client/Config/GoogleConfig.php index 70afc3a..5902660 100644 --- a/Service/ChannelApi/Client/Config/GoogleConfig.php +++ b/Service/ChannelApi/Client/Config/GoogleConfig.php @@ -13,14 +13,14 @@ class GoogleConfig { /** - * @var string + * @var string|null */ - protected $clientId; + protected ?string $clientId = null; /** - * @var string + * @var string|null */ - protected $clientSecret; + protected ?string $clientSecret = null; /** * GoogleConfig constructor diff --git a/Service/ChannelApi/Client/Config/YouTubeConfig.php b/Service/ChannelApi/Client/Config/YouTubeConfig.php index 33be38f..b8b96d2 100644 --- a/Service/ChannelApi/Client/Config/YouTubeConfig.php +++ b/Service/ChannelApi/Client/Config/YouTubeConfig.php @@ -15,12 +15,12 @@ class YouTubeConfig /** * @var string */ - protected $host; + protected string $host; /** * @var string */ - protected $thumbnailDirectory; + protected string $thumbnailDirectory; /** * YouTubeConfig constructor. diff --git a/Service/ChannelApi/Client/GoogleClient.php b/Service/ChannelApi/Client/GoogleClient.php index 5129134..f3a4013 100644 --- a/Service/ChannelApi/Client/GoogleClient.php +++ b/Service/ChannelApi/Client/GoogleClient.php @@ -19,22 +19,22 @@ class GoogleClient /** * @var array */ - public $scope = [\Google_Service_YouTube::YOUTUBE]; + public array $scope = [\Google_Service_YouTube::YOUTUBE]; /** * @var GoogleConfig */ - protected $config; + protected GoogleConfig $config; /** * @var GoogleRedirectService */ - protected $redirect; + protected GoogleRedirectService $redirect; /** * @var LoggerInterface */ - protected $logger; + protected LoggerInterface $logger; /** * GoogleClient constructor. diff --git a/Service/ChannelApi/Client/YouTubeClient.php b/Service/ChannelApi/Client/YouTubeClient.php index 40d2976..b691285 100644 --- a/Service/ChannelApi/Client/YouTubeClient.php +++ b/Service/ChannelApi/Client/YouTubeClient.php @@ -7,6 +7,7 @@ */ namespace Martin1982\LiveBroadcastBundle\Service\ChannelApi\Client; +use DateTimeInterface; use Martin1982\LiveBroadcastBundle\Entity\Channel\ChannelYouTube; use Martin1982\LiveBroadcastBundle\Entity\LiveBroadcast; use Martin1982\LiveBroadcastBundle\Entity\Metadata\StreamEvent; @@ -23,17 +24,17 @@ class YouTubeClient /** * @var YouTubeConfig */ - protected $config; + protected YouTubeConfig $config; /** * @var GoogleClient */ - protected $googleClient; + protected GoogleClient $googleClient; /** * @var \Google_Service_YouTube|null */ - protected $youTubeClient; + protected ?\Google_Service_YouTube $youTubeClient = null; /** * YouTubeClient constructor @@ -124,7 +125,7 @@ public function addThumbnailToBroadcast(\Google_Service_YouTube_LiveBroadcast $y return false; } - $chunkSizeBytes = (1 * 1024 * 1024); + $chunkSizeBytes = (1024 * 1024); $client = $this->youTubeClient->getClient(); if (!$client) { @@ -294,7 +295,7 @@ public function getYoutubeBroadcast(string $youTubeId): ?\Google_Service_YouTube * * @return string|null */ - public function getStreamUrl($streamId): ?string + public function getStreamUrl(string $streamId): ?string { /** @var \Google_Service_YouTube_LiveStream $stream */ $stream = $this->youTubeClient @@ -313,9 +314,9 @@ public function getStreamUrl($streamId): ?string /** * Get a list of live streams * - * @return mixed + * @return array */ - public function getStreamsList() + public function getStreamsList(): array { $response = $this->youTubeClient ->liveBroadcasts @@ -344,8 +345,8 @@ protected function createBroadcastSnippet(LiveBroadcast $plannedBroadcast): \Goo $broadcastSnippet = new \Google_Service_YouTube_LiveBroadcastSnippet(); $broadcastSnippet->setTitle($plannedBroadcast->getName()); $broadcastSnippet->setDescription($plannedBroadcast->getDescription()); - $broadcastSnippet->setScheduledStartTime($start->format(\DateTime::ATOM)); - $broadcastSnippet->setScheduledEndTime($plannedBroadcast->getEndTimestamp()->format(\DateTime::ATOM)); + $broadcastSnippet->setScheduledStartTime($start->format(DateTimeInterface::ATOM)); + $broadcastSnippet->setScheduledEndTime($plannedBroadcast->getEndTimestamp()->format(DateTimeInterface::ATOM)); return $broadcastSnippet; } diff --git a/Service/ChannelApi/FacebookApiService.php b/Service/ChannelApi/FacebookApiService.php index 18f584c..8574e88 100644 --- a/Service/ChannelApi/FacebookApiService.php +++ b/Service/ChannelApi/FacebookApiService.php @@ -26,22 +26,22 @@ class FacebookApiService implements ChannelApiInterface /** * @var string */ - private $applicationId; + private string $applicationId; /** * @var string */ - private $applicationSecret; + private string $applicationSecret; /** * @var EntityManager */ - private $entityManager; + private EntityManager $entityManager; /** - * @var FacebookSDK + * @var FacebookSDK|null */ - private $facebookSDK; + private ?FacebookSDK $facebookSDK = null; /** * FacebookApiService constructor. @@ -50,7 +50,7 @@ class FacebookApiService implements ChannelApiInterface * @param string|null $applicationId * @param string|null $applicationSecret */ - public function __construct(EntityManager $entityManager, $applicationId = null, $applicationSecret = null) + public function __construct(EntityManager $entityManager, string $applicationId = null, string $applicationSecret = null) { $this->applicationId = (string) $applicationId; $this->applicationSecret = (string) $applicationSecret; @@ -193,13 +193,13 @@ public function removeLiveEvent(LiveBroadcast $broadcast, AbstractChannel $chann } /** - * @param string $userAccessToken + * @param string|null $userAccessToken * * @return AccessToken|null * * @throws LiveBroadcastOutputException */ - public function getLongLivedAccessToken($userAccessToken): ?AccessToken + public function getLongLivedAccessToken(?string $userAccessToken): ?AccessToken { $this->ensureSdkLoaded(); diff --git a/Service/ChannelApi/YouTubeApiService.php b/Service/ChannelApi/YouTubeApiService.php index a0fc33b..a2f9d4f 100644 --- a/Service/ChannelApi/YouTubeApiService.php +++ b/Service/ChannelApi/YouTubeApiService.php @@ -24,24 +24,24 @@ class YouTubeApiService implements ChannelApiInterface { /** - * @var string + * @var string|null */ - protected $host; + protected ?string $host = null; /** * @var LoggerInterface */ - protected $logger; + protected LoggerInterface $logger; /** * @var EntityManager */ - protected $entityManager; + protected EntityManager $entityManager; /** * @var YouTubeClient */ - protected $client; + protected YouTubeClient $client; /** * YouTubeApiService constructor diff --git a/Service/ChannelValidatorService.php b/Service/ChannelValidatorService.php index 6bbfb56..da65c2d 100644 --- a/Service/ChannelValidatorService.php +++ b/Service/ChannelValidatorService.php @@ -29,17 +29,17 @@ class ChannelValidatorService /** * @var EntityManagerInterface */ - protected $entityManager; + protected EntityManagerInterface $entityManager; /** * @var ValidatorInterface */ - protected $validator; + protected ValidatorInterface $validator; /** * @var KernelInterface */ - protected $kernel; + protected KernelInterface $kernel; /** * ChannelValidatorService constructor. diff --git a/Service/GoogleRedirectService.php b/Service/GoogleRedirectService.php index 6a8e00d..bbb7169 100644 --- a/Service/GoogleRedirectService.php +++ b/Service/GoogleRedirectService.php @@ -8,8 +8,6 @@ namespace Martin1982\LiveBroadcastBundle\Service; use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException; -use Symfony\Component\Routing\Exception\InvalidParameterException; -use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\RouterInterface; @@ -21,12 +19,12 @@ class GoogleRedirectService /** * @var RouterInterface */ - protected $router; + protected RouterInterface $router; /** - * @var string + * @var string|null */ - protected $redirectRoute; + protected ?string $redirectRoute; /** * GoogleRedirectService constructor @@ -34,7 +32,7 @@ class GoogleRedirectService * @param RouterInterface $router * @param string|null $redirectRoute */ - public function __construct(RouterInterface $router, $redirectRoute = null) + public function __construct(RouterInterface $router, ?string $redirectRoute = null) { $this->router = $router; $this->redirectRoute = $redirectRoute; @@ -57,10 +55,6 @@ public function getOAuthRedirectUrl(): string ); } catch (RouteNotFoundException $exception) { throw new LiveBroadcastOutputException($exception->getMessage()); - } catch (MissingMandatoryParametersException $exception) { - throw new LiveBroadcastOutputException($exception->getMessage()); - } catch (InvalidParameterException $exception) { - throw new LiveBroadcastOutputException($exception->getMessage()); } } } diff --git a/Service/StreamInput/InputFile.php b/Service/StreamInput/InputFile.php index 916cb7c..5fc2b15 100644 --- a/Service/StreamInput/InputFile.php +++ b/Service/StreamInput/InputFile.php @@ -17,7 +17,7 @@ class InputFile implements InputInterface { /** - * @var MediaFile + * @var MediaFile|AbstractMedia */ private $media; diff --git a/Service/StreamInput/InputRtmp.php b/Service/StreamInput/InputRtmp.php index 7579da2..d771c0f 100644 --- a/Service/StreamInput/InputRtmp.php +++ b/Service/StreamInput/InputRtmp.php @@ -17,7 +17,7 @@ class InputRtmp implements InputInterface { /** - * @var MediaRtmp + * @var MediaRtmp|AbstractMedia */ private $media; diff --git a/Service/StreamInput/InputUrl.php b/Service/StreamInput/InputUrl.php index d51cd2e..35b3874 100644 --- a/Service/StreamInput/InputUrl.php +++ b/Service/StreamInput/InputUrl.php @@ -17,7 +17,7 @@ class InputUrl implements InputInterface { /** - * @var MediaUrl + * @var MediaUrl|AbstractMedia */ private $media; diff --git a/Service/StreamInputService.php b/Service/StreamInputService.php index 18b94f0..1475282 100644 --- a/Service/StreamInputService.php +++ b/Service/StreamInputService.php @@ -19,13 +19,13 @@ class StreamInputService /** * @var InputInterface[] */ - private $streamInputs = []; + private array $streamInputs = []; /** * @param InputInterface $streamInput * @param string $media */ - public function addStreamInput(InputInterface $streamInput, $media): void + public function addStreamInput(InputInterface $streamInput, string $media): void { $this->streamInputs[$media] = $streamInput; } diff --git a/Service/StreamOutput/AbstractOutput.php b/Service/StreamOutput/AbstractOutput.php index a80928a..a3d048c 100644 --- a/Service/StreamOutput/AbstractOutput.php +++ b/Service/StreamOutput/AbstractOutput.php @@ -15,12 +15,12 @@ abstract class AbstractOutput implements OutputInterface /** * @var string|null */ - protected $lastError; + protected ?string $lastError = null; /** * @var AbstractChannel|null */ - protected $channel; + protected ?AbstractChannel $channel = null; /** * @param AbstractChannel $channel diff --git a/Service/StreamOutput/OutputFacebook.php b/Service/StreamOutput/OutputFacebook.php index b9a0160..bdf9903 100644 --- a/Service/StreamOutput/OutputFacebook.php +++ b/Service/StreamOutput/OutputFacebook.php @@ -6,6 +6,7 @@ */ namespace Martin1982\LiveBroadcastBundle\Service\StreamOutput; +use Martin1982\LiveBroadcastBundle\Entity\Channel\AbstractChannel; use Martin1982\LiveBroadcastBundle\Entity\Channel\ChannelFacebook; use Martin1982\LiveBroadcastBundle\Entity\LiveBroadcast; use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException; @@ -17,19 +18,19 @@ class OutputFacebook extends AbstractOutput implements DynamicStreamUrlInterface { /** - * @var ChannelFacebook + * @var AbstractChannel|ChannelFacebook|null */ - protected $channel; + protected ?AbstractChannel $channel = null; /** * @var FacebookApiService */ - protected $api; + protected FacebookApiService $api; /** * @var LiveBroadcast|null */ - protected $broadcast; + protected ?LiveBroadcast $broadcast = null; /** * OutputFacebook constructor diff --git a/Service/StreamOutput/OutputTwitch.php b/Service/StreamOutput/OutputTwitch.php index 5abe9e1..8dbd4f2 100644 --- a/Service/StreamOutput/OutputTwitch.php +++ b/Service/StreamOutput/OutputTwitch.php @@ -6,6 +6,7 @@ */ namespace Martin1982\LiveBroadcastBundle\Service\StreamOutput; +use Martin1982\LiveBroadcastBundle\Entity\Channel\AbstractChannel; use Martin1982\LiveBroadcastBundle\Entity\Channel\ChannelTwitch; use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException; @@ -15,9 +16,9 @@ class OutputTwitch extends AbstractOutput { /** - * @var ChannelTwitch + * @var ChannelTwitch|AbstractChannel|null */ - protected $channel; + protected ?AbstractChannel $channel = null; /** * Get the output parameters for streaming. diff --git a/Service/StreamOutput/OutputYouTube.php b/Service/StreamOutput/OutputYouTube.php index ecfed3d..b78c5a3 100644 --- a/Service/StreamOutput/OutputYouTube.php +++ b/Service/StreamOutput/OutputYouTube.php @@ -6,6 +6,7 @@ */ namespace Martin1982\LiveBroadcastBundle\Service\StreamOutput; +use Martin1982\LiveBroadcastBundle\Entity\Channel\AbstractChannel; use Martin1982\LiveBroadcastBundle\Entity\Channel\ChannelYouTube; use Martin1982\LiveBroadcastBundle\Entity\LiveBroadcast; use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException; @@ -17,19 +18,19 @@ class OutputYouTube extends AbstractOutput implements DynamicStreamUrlInterface { /** - * @var ChannelYouTube + * @var ChannelYouTube|AbstractChannel|null */ - protected $channel; + protected ?AbstractChannel $channel = null; /** * @var YouTubeApiService */ - protected $api; + protected YouTubeApiService $api; /** * @var LiveBroadcast|null */ - protected $broadcast; + protected ?LiveBroadcast $broadcast = null; /** * OutputYouTube constructor diff --git a/Service/StreamOutputService.php b/Service/StreamOutputService.php index 929cf3c..fe3a197 100644 --- a/Service/StreamOutputService.php +++ b/Service/StreamOutputService.php @@ -19,13 +19,13 @@ class StreamOutputService /** * @var OutputInterface[] */ - private $streamOutputs = []; + private array $streamOutputs = []; /** * @param OutputInterface $streamOutput * @param string $platform */ - public function addStreamOutput(OutputInterface $streamOutput, $platform): void + public function addStreamOutput(OutputInterface $streamOutput, string $platform): void { $this->streamOutputs[$platform] = $streamOutput; } diff --git a/Service/ThumbnailUploadService.php b/Service/ThumbnailUploadService.php index 1d12914..bb76a5e 100644 --- a/Service/ThumbnailUploadService.php +++ b/Service/ThumbnailUploadService.php @@ -18,14 +18,14 @@ class ThumbnailUploadService /** * @var string */ - private $targetDirectory; + private string $targetDirectory; /** * ThumbnailUploader constructor * * @param string $targetDirectory */ - public function __construct($targetDirectory) + public function __construct(string $targetDirectory) { $this->targetDirectory = $targetDirectory; } diff --git a/Tests/Broadcaster/AbstractSchedulerCommandsTest.php b/Tests/Broadcaster/AbstractSchedulerCommandsTest.php index a1b5b14..f7ae690 100644 --- a/Tests/Broadcaster/AbstractSchedulerCommandsTest.php +++ b/Tests/Broadcaster/AbstractSchedulerCommandsTest.php @@ -24,7 +24,7 @@ class AbstractSchedulerCommandsTest extends TestCase private $schedulerCommands; /** - * Setup a basic test object + * Set up a basic test object */ public function setUp(): void { @@ -57,8 +57,6 @@ public function testGetRunningProcesses(): void /** * Test the FFMPEG log directory setter - * - * @throws \ReflectionException */ public function testFFMpegLogDirectory(): void { @@ -74,7 +72,7 @@ public function testFFMpegLogDirectory(): void } /** - * Test if a stream can looped + * Test if a stream can loop */ public function testLooping(): void { diff --git a/Tests/Broadcaster/RunningBroadcastTest.php b/Tests/Broadcaster/RunningBroadcastTest.php index 71695e3..20f3e83 100644 --- a/Tests/Broadcaster/RunningBroadcastTest.php +++ b/Tests/Broadcaster/RunningBroadcastTest.php @@ -34,19 +34,19 @@ public function testGetMethods(): void */ public function testIsValid(): void { - $running = new RunningBroadcast(null, null, null, null); + $running = new RunningBroadcast(0, 0, 0, 'test'); self::assertFalse($running->isValid('')); - $running = new RunningBroadcast(1, null, null, null); + $running = new RunningBroadcast(1, 0, 0, 'test'); self::assertFalse($running->isValid('')); - $running = new RunningBroadcast(null, 2, null, null); + $running = new RunningBroadcast(0, 2, 0, 'test'); self::assertFalse($running->isValid('')); - $running = new RunningBroadcast(null, 2, 3, null); + $running = new RunningBroadcast(0, 2, 3, 'test'); self::assertFalse($running->isValid('')); - $running = new RunningBroadcast(1, 2, null, null); + $running = new RunningBroadcast(1, 2, 0, 'test'); self::assertFalse($running->isValid('')); $running = new RunningBroadcast(1, 2, 3, 'unit'); @@ -58,13 +58,11 @@ public function testIsValid(): void /** * Test the isBroadcasting method - * - * @throws \ReflectionException */ public function testIsBroadcasting(): void { /* Create a running broadcast with string values as id's */ - $running = new RunningBroadcast('5', '2', '6', 'test'); + $running = new RunningBroadcast(5, 2, 6, 'test'); $liveBroadcast = $this->getLiveBroadcast(5); $channel = $this->getChannelTwitch(6); @@ -86,10 +84,8 @@ public function testIsBroadcasting(): void * @param int $channelId * * @return ChannelTwitch - * - * @throws \ReflectionException */ - private function getChannelTwitch($channelId): ChannelTwitch + private function getChannelTwitch(int $channelId): ChannelTwitch { $channel = new ChannelTwitch(); $reflection = new \ReflectionClass($channel); @@ -104,10 +100,8 @@ private function getChannelTwitch($channelId): ChannelTwitch * @param int $broadcastId * * @return LiveBroadcast - * - * @throws \ReflectionException */ - private function getLiveBroadcast($broadcastId): LiveBroadcast + private function getLiveBroadcast(int $broadcastId): LiveBroadcast { $liveBroadcast = new LiveBroadcast(); $reflection = new \ReflectionClass($liveBroadcast); diff --git a/Tests/Broadcaster/SchedulerCommandsTest.php b/Tests/Broadcaster/SchedulerCommandsTest.php index 7db4a9d..2604396 100644 --- a/Tests/Broadcaster/SchedulerCommandsTest.php +++ b/Tests/Broadcaster/SchedulerCommandsTest.php @@ -163,7 +163,7 @@ public function testGetChannelId(): void { $command = $this->getSchedulerCommands(); self::assertNull($command->getChannelId('')); - self::assertNull($command->getChannelId('channelid=12')); + self::assertNull($command->getChannelId('channel_id=12')); // @codingStandardsIgnoreLine $channelId = $command->getChannelId('1234 ffmpeg -re -i /path/to/video.mp4 -vcodec copy -acodec copy -f flv rtmp://live-ams.twitch.tv/app/ -metadata env=unit_test -metadata broadcast_id=1337 -metadata channel_id=5'); diff --git a/Tests/DependencyInjection/Compiler/AddChannelApiPassTest.php b/Tests/DependencyInjection/Compiler/AddChannelApiPassTest.php index 0fb24ba..dae23fe 100644 --- a/Tests/DependencyInjection/Compiler/AddChannelApiPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddChannelApiPassTest.php @@ -22,7 +22,7 @@ class AddChannelApiPassTest extends TestCase /** * @var AddChannelApiPass */ - private $compilerPass; + private AddChannelApiPass $compilerPass; /** * Setup basic object diff --git a/Tests/DependencyInjection/Compiler/AddStreamInputPassTest.php b/Tests/DependencyInjection/Compiler/AddStreamInputPassTest.php index 8bdb623..b0c6c33 100644 --- a/Tests/DependencyInjection/Compiler/AddStreamInputPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddStreamInputPassTest.php @@ -22,7 +22,7 @@ class AddStreamInputPassTest extends TestCase /** * @var AddStreamInputPass */ - private $compilerPass; + private AddStreamInputPass $compilerPass; /** * diff --git a/Tests/DependencyInjection/Compiler/AddStreamOutputPassTest.php b/Tests/DependencyInjection/Compiler/AddStreamOutputPassTest.php index a885597..db4d423 100644 --- a/Tests/DependencyInjection/Compiler/AddStreamOutputPassTest.php +++ b/Tests/DependencyInjection/Compiler/AddStreamOutputPassTest.php @@ -21,7 +21,7 @@ class AddStreamOutputPassTest extends TestCase /** * @var AddStreamOutputPass */ - private $compilerPass; + private AddStreamOutputPass $compilerPass; /** * diff --git a/Tests/Entity/Channel/ChannelTwitchTest.php b/Tests/Entity/Channel/ChannelTwitchTest.php index 445cfab..763c43c 100644 --- a/Tests/Entity/Channel/ChannelTwitchTest.php +++ b/Tests/Entity/Channel/ChannelTwitchTest.php @@ -55,6 +55,6 @@ public function testIsEntityConfigured(): void $channel = new ChannelTwitch(); $configuration = []; - self::assertTrue($channel::isEntityConfigured($configuration)); + self::assertFalse($channel::isEntityConfigured($configuration)); } } diff --git a/Tests/Entity/Media/AbstractMediaTest.php b/Tests/Entity/Media/AbstractMediaTest.php index 6180abf..a3fd87b 100644 --- a/Tests/Entity/Media/AbstractMediaTest.php +++ b/Tests/Entity/Media/AbstractMediaTest.php @@ -17,8 +17,6 @@ class AbstractMediaTest extends TestCase { /** * Test converting the object to a string - * - * @throws \ReflectionException */ public function testToString(): void { diff --git a/Tests/Entity/Metadata/StreamEventTest.php b/Tests/Entity/Metadata/StreamEventTest.php index 947b5e4..92b1d72 100644 --- a/Tests/Entity/Metadata/StreamEventTest.php +++ b/Tests/Entity/Metadata/StreamEventTest.php @@ -20,12 +20,10 @@ class StreamEventTest extends TestCase /** * @var StreamEvent */ - private $streamEvent; + private StreamEvent $streamEvent; /** * Setup default test object - * - * @throws \ReflectionException */ public function setUp(): void { diff --git a/Tests/EventListener/StreamAnnouncementListenerTest.php b/Tests/EventListener/StreamAnnouncementListenerTest.php index 6247e0c..4be2bb3 100644 --- a/Tests/EventListener/StreamAnnouncementListenerTest.php +++ b/Tests/EventListener/StreamAnnouncementListenerTest.php @@ -38,7 +38,7 @@ class StreamAnnouncementListenerTest extends TestCase /** * @var Envelope */ - protected $envelope; + protected Envelope $envelope; /** * Setup mock objects diff --git a/Tests/EventListener/ThumbnailUploadListenerTest.php b/Tests/EventListener/ThumbnailUploadListenerTest.php index 975282c..d087ffb 100644 --- a/Tests/EventListener/ThumbnailUploadListenerTest.php +++ b/Tests/EventListener/ThumbnailUploadListenerTest.php @@ -32,7 +32,7 @@ class ThumbnailUploadListenerTest extends TestCase /** * @var ThumbnailUploadListener */ - private $eventListener; + private ThumbnailUploadListener $eventListener; /** * diff --git a/Tests/Service/BroadcastManagerTest.php b/Tests/Service/BroadcastManagerTest.php index 9c24fe3..4d9985d 100644 --- a/Tests/Service/BroadcastManagerTest.php +++ b/Tests/Service/BroadcastManagerTest.php @@ -10,9 +10,8 @@ use Doctrine\Common\Collections\ArrayCollection; use Doctrine\ORM\EntityManager; use Doctrine\ORM\EntityRepository; +use Doctrine\ORM\Exception\ORMException; use Doctrine\ORM\OptimisticLockException; -use Doctrine\ORM\ORMException; -use Doctrine\ORM\ORMInvalidArgumentException; use Martin1982\LiveBroadcastBundle\Entity\Channel\ChannelFacebook; use Martin1982\LiveBroadcastBundle\Entity\Channel\ChannelYouTube; use Martin1982\LiveBroadcastBundle\Entity\LiveBroadcast; @@ -20,6 +19,7 @@ use Martin1982\LiveBroadcastBundle\Entity\Metadata\StreamEvent; use Martin1982\LiveBroadcastBundle\Entity\Metadata\StreamEventRepository; use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastException; +use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException; use Martin1982\LiveBroadcastBundle\Service\BroadcastManager; use Martin1982\LiveBroadcastBundle\Service\ChannelApi\ChannelApiInterface; use Martin1982\LiveBroadcastBundle\Service\ChannelApi\ChannelApiStack; @@ -208,6 +208,7 @@ public function testPreDelete(): void * Test sending an end signal * * @throws LiveBroadcastException + * @throws ORMException|\Doctrine\ORM\ORMException */ public function testSendEndSignal(): void { @@ -254,6 +255,7 @@ public function testGetEventsRepository(): void /** * Test sending an end signal + * @throws ORMException|\Doctrine\ORM\ORMException */ public function testSendEndSignalLockException(): void { @@ -288,6 +290,9 @@ public function testSendEndSignalLockException(): void /** * Test sending an end signal + * + * @throws ORMException + * @throws \Doctrine\ORM\ORMException */ public function testSendEndSignalArgumentException(): void { @@ -303,7 +308,7 @@ public function testSendEndSignalArgumentException(): void $api = $this->createMock(ChannelApiInterface::class); $api->expects(self::atLeastOnce()) ->method('sendEndSignal') - ->willThrowException(new ORMInvalidArgumentException('some error')); + ->willThrowException(new LiveBroadcastOutputException('some error')); $this->stack->expects(self::atLeastOnce()) ->method('getApiForChannel') @@ -322,6 +327,9 @@ public function testSendEndSignalArgumentException(): void /** * Test sending an end signal + * + * @throws ORMException + * @throws \Doctrine\ORM\ORMException */ public function testSendEndSignalORMException(): void { diff --git a/Tests/Service/BroadcastStarterTest.php b/Tests/Service/BroadcastStarterTest.php index b0c26bd..3958be3 100644 --- a/Tests/Service/BroadcastStarterTest.php +++ b/Tests/Service/BroadcastStarterTest.php @@ -52,7 +52,7 @@ public function testStartBroadcast(): void $inputInterface = $this->createMock(InputInterface::class); $inputInterface->expects(self::atLeastOnce()) ->method('generateInputCmd') - ->willReturn('inputcmd'); + ->willReturn('input_cmd'); $outputInterface = $this->createMock(DynamicStreamUrlInterface::class); $outputInterface->expects(self::atLeastOnce()) diff --git a/Tests/Service/ChannelApi/Client/Config/GoogleConfigTest.php b/Tests/Service/ChannelApi/Client/Config/GoogleConfigTest.php index 06dba25..d715605 100644 --- a/Tests/Service/ChannelApi/Client/Config/GoogleConfigTest.php +++ b/Tests/Service/ChannelApi/Client/Config/GoogleConfigTest.php @@ -18,7 +18,7 @@ class GoogleConfigTest extends TestCase /** * @var GoogleConfig */ - protected $defaultConfig; + protected GoogleConfig $defaultConfig; /** * Test getting the client id diff --git a/Tests/Service/ChannelApi/Client/Config/YouTubeConfigTest.php b/Tests/Service/ChannelApi/Client/Config/YouTubeConfigTest.php index 27648f3..64f3bb3 100644 --- a/Tests/Service/ChannelApi/Client/Config/YouTubeConfigTest.php +++ b/Tests/Service/ChannelApi/Client/Config/YouTubeConfigTest.php @@ -18,7 +18,7 @@ class YouTubeConfigTest extends TestCase /** * @var YouTubeConfig */ - protected $config; + protected YouTubeConfig $config; /** * Test getting the host diff --git a/Tests/Service/ChannelApi/FacebookApiServiceMock.php b/Tests/Service/ChannelApi/FacebookApiServiceMock.php index 0354eb3..c6614b3 100644 --- a/Tests/Service/ChannelApi/FacebookApiServiceMock.php +++ b/Tests/Service/ChannelApi/FacebookApiServiceMock.php @@ -23,8 +23,6 @@ class FacebookApiServiceMock extends FacebookApiService */ public function setFacebookSdk(FacebookSDK $sdk): void { - if ($sdk) { - throw new SDKException('Something went wrong...'); - } + throw new SDKException('Something went wrong...'); } } diff --git a/Tests/Service/ChannelApi/FacebookApiServiceTest.php b/Tests/Service/ChannelApi/FacebookApiServiceTest.php index 6a2be31..1b4046c 100644 --- a/Tests/Service/ChannelApi/FacebookApiServiceTest.php +++ b/Tests/Service/ChannelApi/FacebookApiServiceTest.php @@ -393,7 +393,7 @@ public function testGetLongLivedAccessTokenWithoutToken(): void $facebook = $this->getFacebookApiService(); $facebook->setFacebookSdk($sdk); - $facebook->getLongLivedAccessToken(false); + $facebook->getLongLivedAccessToken(''); } /** @@ -409,7 +409,7 @@ public function testGetLongLivedAccessTokenSdkError(): void $facebook = $this->getFacebookApiService(); $facebook->setFacebookSdk($sdk); - $facebook->getLongLivedAccessToken('abcdef'); + $facebook->getLongLivedAccessToken('a_token'); } /** @@ -431,11 +431,11 @@ public function testGetLongLivedAccessToken(): void $facebook = $this->getFacebookApiService(); $facebook->setFacebookSdk($sdk); - $facebook->getLongLivedAccessToken('ddadsa'); + $facebook->getLongLivedAccessToken('token'); } /** - * Test that this method doesn't do anything with a incompatible channel + * Test that this method doesn't do anything with an incompatible channel * * @throws LiveBroadcastOutputException */ @@ -496,7 +496,7 @@ public function testGetStreamUrlFacebookError(): void $channel = $this->createMock(ChannelFacebook::class); $channel->expects(self::atLeastOnce()) ->method('getAccessToken') - ->willReturn('dksakmdsa'); + ->willReturn('access_granted'); $streamEvent = $this->createMock(StreamEvent::class); $streamEvent->expects(self::atLeastOnce()) @@ -547,7 +547,7 @@ public function testGetStreamUrl(): void $channel = $this->createMock(ChannelFacebook::class); $channel->expects(self::atLeastOnce()) ->method('getAccessToken') - ->willReturn('dksakmdsa'); + ->willReturn('access_granted'); $streamEvent = $this->createMock(StreamEvent::class); $streamEvent->expects(self::atLeastOnce()) @@ -571,7 +571,7 @@ public function testGetStreamUrl(): void } /** - * Test sending a end signal to a non Facebook channel + * Test sending an end signal to a non Facebook channel * * @throws LiveBroadcastOutputException */ diff --git a/Tests/Service/ChannelApi/YouTubeApiServiceTest.php b/Tests/Service/ChannelApi/YouTubeApiServiceTest.php index 73ab417..49c6421 100644 --- a/Tests/Service/ChannelApi/YouTubeApiServiceTest.php +++ b/Tests/Service/ChannelApi/YouTubeApiServiceTest.php @@ -193,6 +193,7 @@ public function testUpdateLiveEvent(): void /** * Test that when no event is available an exception is thrown + * @throws \Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastException */ public function testGetStreamUrlForNoEvent(): void { diff --git a/Tests/Service/GoogleRedirectServiceTest.php b/Tests/Service/GoogleRedirectServiceTest.php index ea499be..5e10694 100644 --- a/Tests/Service/GoogleRedirectServiceTest.php +++ b/Tests/Service/GoogleRedirectServiceTest.php @@ -10,8 +10,6 @@ use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastOutputException; use Martin1982\LiveBroadcastBundle\Service\GoogleRedirectService; use PHPUnit\Framework\TestCase; -use Symfony\Component\Routing\Exception\InvalidParameterException; -use Symfony\Component\Routing\Exception\MissingMandatoryParametersException; use Symfony\Component\Routing\Exception\RouteNotFoundException; use Symfony\Component\Routing\RouterInterface; @@ -70,7 +68,7 @@ public function testMissingMandatoryParameters(): void $router = $this->createMock(RouterInterface::class); $router->expects(static::once()) ->method('generate') - ->willThrowException(new MissingMandatoryParametersException()); + ->willThrowException(new LiveBroadcastOutputException()); $redirectRoute = 'test'; @@ -90,7 +88,7 @@ public function testInvalidParameter(): void $router = $this->createMock(RouterInterface::class); $router->expects(static::once()) ->method('generate') - ->willThrowException(new InvalidParameterException()); + ->willThrowException(new LiveBroadcastOutputException()); $redirectRoute = 'test'; diff --git a/Tests/Service/StreamInput/InputFileTest.php b/Tests/Service/StreamInput/InputFileTest.php index 397cc46..1842807 100644 --- a/Tests/Service/StreamInput/InputFileTest.php +++ b/Tests/Service/StreamInput/InputFileTest.php @@ -20,7 +20,7 @@ class InputFileTest extends TestCase /** * @var InputFile */ - private $file; + private InputFile $file; /** * diff --git a/Tests/Service/StreamInput/InputRtmpTest.php b/Tests/Service/StreamInput/InputRtmpTest.php index 8843d0e..d108556 100644 --- a/Tests/Service/StreamInput/InputRtmpTest.php +++ b/Tests/Service/StreamInput/InputRtmpTest.php @@ -23,7 +23,7 @@ class InputRtmpTest extends TestCase /** * @var InputRtmp */ - private $serverAddress; + private InputRtmp $serverAddress; /** * Setup a basic RTMP object diff --git a/Tests/Service/StreamInput/InputUrlTest.php b/Tests/Service/StreamInput/InputUrlTest.php index 53da48f..455e727 100644 --- a/Tests/Service/StreamInput/InputUrlTest.php +++ b/Tests/Service/StreamInput/InputUrlTest.php @@ -20,7 +20,7 @@ class InputUrlTest extends TestCase /** * @var InputUrl */ - private $inputUrl; + private InputUrl $inputUrl; /** * diff --git a/Tests/Service/StreamOutput/OutputFacebookTest.php b/Tests/Service/StreamOutput/OutputFacebookTest.php index 6fab1c9..867a04e 100644 --- a/Tests/Service/StreamOutput/OutputFacebookTest.php +++ b/Tests/Service/StreamOutput/OutputFacebookTest.php @@ -25,7 +25,7 @@ class OutputFacebookTest extends TestCase /** * @var ChannelFacebook */ - private $facebookChannel; + private ChannelFacebook $facebookChannel; /** * @var FacebookApiService|MockObject @@ -33,7 +33,7 @@ class OutputFacebookTest extends TestCase private $api; /** - * Setup a testable Facebook channel + * Set up a testable Facebook channel */ public function setUp(): void { @@ -54,7 +54,7 @@ public function tesImplementsOutputInterface(): void } /** - * Test the generate output command without a channel + * Test the output generation command without a channel */ public function testGenerateOutputCmdWithoutChannel(): void { @@ -64,7 +64,7 @@ public function testGenerateOutputCmdWithoutChannel(): void } /** - * Test the generate output command with an invalid channel + * Test the output generation command with an invalid channel */ public function testGenerateOutputCmdWithInvalidChannel(): void { @@ -77,7 +77,7 @@ public function testGenerateOutputCmdWithInvalidChannel(): void } /** - * Test the generate output command without a stream url set + * Test the output generation command without a stream url set */ public function testGenerateOutputCmdWithoutStreamUrl(): void { diff --git a/Tests/Service/StreamOutput/OutputTwitchTest.php b/Tests/Service/StreamOutput/OutputTwitchTest.php index 7b20b96..99a4ed4 100644 --- a/Tests/Service/StreamOutput/OutputTwitchTest.php +++ b/Tests/Service/StreamOutput/OutputTwitchTest.php @@ -21,10 +21,10 @@ class OutputTwitchTest extends TestCase /** * @var ChannelTwitch */ - private $twitchChannel; + private ChannelTwitch $twitchChannel; /** - * Setup a testable Twitch channel. + * Set up a testable Twitch channel. */ public function setUp(): void { @@ -43,7 +43,7 @@ public function tesImplementsOutputInterface(): void } /** - * Test the generate output command without a channel + * Test the output generation command without a channel */ public function testGenerateOutputCmdWithoutChannel(): void { @@ -53,7 +53,7 @@ public function testGenerateOutputCmdWithoutChannel(): void } /** - * Test the generate output command with an invalid channel + * Test the output generation command with an invalid channel */ public function testGenerateOutputCmdWithInvalidChannel(): void { diff --git a/Tests/Service/StreamOutput/OutputYouTubeTest.php b/Tests/Service/StreamOutput/OutputYouTubeTest.php index 4c4f4ab..8b6f5bc 100644 --- a/Tests/Service/StreamOutput/OutputYouTubeTest.php +++ b/Tests/Service/StreamOutput/OutputYouTubeTest.php @@ -22,10 +22,10 @@ class OutputYouTubeTest extends TestCase /** * @var OutputYouTube */ - private $youTube; + private OutputYouTube $youTube; /** - * Setup a testable Facebook channel + * Set up a testable Facebook channel */ public function setUp(): void { @@ -52,6 +52,7 @@ public function testChannelType(): void /** * Test generating an output throws an exception + * @throws \Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastException */ public function testGenerateOutputCmdException(): void { @@ -61,6 +62,7 @@ public function testGenerateOutputCmdException(): void /** * Test that no stream url throws an exception + * @throws \Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastException */ public function testNoStreamUrlException(): void { diff --git a/Validator/Constraints/CanStreamToChannelValidator.php b/Validator/Constraints/CanStreamToChannelValidator.php index 9532fcd..05f310d 100644 --- a/Validator/Constraints/CanStreamToChannelValidator.php +++ b/Validator/Constraints/CanStreamToChannelValidator.php @@ -21,7 +21,7 @@ class CanStreamToChannelValidator extends ConstraintValidator /** * @var StreamOutputService */ - public $outputService; + public StreamOutputService $outputService; /** * CanStreamToChannelValidator constructor. @@ -36,28 +36,28 @@ public function __construct(StreamOutputService $outputService) /** * Validate streaming to a channel * - * @param AbstractChannel $channel + * @param AbstractChannel $value * @param Constraint $constraint */ - public function validate($channel, Constraint $constraint): void + public function validate($value, Constraint $constraint): void { if (!$constraint instanceof CanStreamToChannel) { throw new UnexpectedTypeException($constraint, CanStreamToChannel::class); } - if (null === $channel || '' === $channel) { + if (null === $value || '' === $value) { return; } - if (!$channel instanceof AbstractChannel) { - throw new UnexpectedValueException($channel, AbstractChannel::class); + if (!$value instanceof AbstractChannel) { + throw new UnexpectedValueException($value, AbstractChannel::class); } // validate abstract channel try { - $hasOutput = $this->outputService->testOutput($channel); + $hasOutput = $this->outputService->testOutput($value); if (false === $hasOutput) { - throw new LiveBroadcastOutputException(sprintf('Channel \'%s\' is no longer valid...', $channel->getChannelName())); + throw new LiveBroadcastOutputException(sprintf('Channel \'%s\' is no longer valid...', $value->getChannelName())); } } catch (\Exception $exception) { $this->context->buildViolation($constraint->message) @@ -68,6 +68,6 @@ public function validate($channel, Constraint $constraint): void return; } - $channel->setIsHealthy(true); + $value->setIsHealthy(true); } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7dbd454..1dc7ff0 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -16,7 +16,7 @@ - ./Tests + ./Tests