Skip to content

Commit

Permalink
Update code inspections
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin de Keijzer committed Mar 3, 2022
1 parent ab284eb commit 9ad6a21
Show file tree
Hide file tree
Showing 10 changed files with 84 additions and 75 deletions.
4 changes: 2 additions & 2 deletions Admin/Block/FacebookBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ class FacebookBlockService extends AbstractBlockService
/**
* @var FacebookApiService
*/
protected $apiService;
protected FacebookApiService $apiService;

/**
* @var ChannelAdmin
*/
protected $admin;
protected ChannelAdmin $admin;

/**
* FacebookBlockService constructor
Expand Down
14 changes: 2 additions & 12 deletions Admin/Block/YouTubeBlockService.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
*/
namespace Martin1982\LiveBroadcastSonataAdminBundle\Admin\Block;

use Google_Client;
use Martin1982\LiveBroadcastBundle\Exception\LiveBroadcastException;
use Martin1982\LiveBroadcastBundle\Service\ChannelApi\Client\GoogleClient;
use Sonata\BlockBundle\Block\BlockContextInterface;
use Sonata\BlockBundle\Block\Service\AbstractBlockService;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Session\Session;
use Twig\Environment;

/**
Expand All @@ -25,12 +23,12 @@ class YouTubeBlockService extends AbstractBlockService
/**
* @var GoogleClient
*/
protected $googleClient;
protected GoogleClient $googleClient;

/**
* @var RequestStack
*/
protected $requestStack;
protected RequestStack $requestStack;

/**
* YouTubeBlockService constructor
Expand Down Expand Up @@ -58,20 +56,12 @@ public function __construct(Environment $twig, GoogleClient $googleClient, Reque
public function execute(BlockContextInterface $blockContext, Response $response = null): Response
{
$client = $this->googleClient->getClient();
if (!$client instanceof Google_Client) {
throw new LiveBroadcastException('Could not load the google client');
}

$request = $this->requestStack->getCurrentRequest();
if (!$request) {
$request = new Request();
}

$session = $request->getSession();
if (!$session) {
$request->setSession(new Session());
}

$refreshToken = $session->get('youTubeRefreshToken');
if ($refreshToken) {
$client->fetchAccessTokenWithRefreshToken($refreshToken);
Expand Down
44 changes: 25 additions & 19 deletions Admin/ChannelAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ChannelAdmin extends AbstractAdmin
/**
* @var array
*/
protected $subclassConfigs = [];
protected array $subclassConfigs = [];

/**
* ChannelAdmin constructor
Expand All @@ -43,9 +43,13 @@ public function __construct(string $code, string $class, string $baseControllerN
}

/**
* {@inheritdoc}
* Get the correct channel template.
*
* @param string $name
*
* @return string
*/
public function getTemplate($name): string
public function getTemplate(string $name): string
{
$subject = $this->getSubject();

Expand All @@ -65,15 +69,15 @@ public function getTemplate($name): string
*
* @param array $configs
*/
public function setSubclassConfigs($configs): void
public function setSubclassConfigs(array $configs): void
{
$this->subclassConfigs = $configs;
}

/**
* @param AbstractChannel[] $subclasses
*/
public function setConfiguredSubclasses($subclasses): void
public function setConfiguredSubclasses(array $subclasses): void
{
$configuredSubclasses = [];
$config = $this->subclassConfigs;
Expand All @@ -88,7 +92,9 @@ public function setConfiguredSubclasses($subclasses): void
}

/**
* {@inheritdoc}
* Configure extra admin routes.
*
* @param RouteCollectionInterface $collection
*/
protected function configureRoutes(RouteCollectionInterface $collection): void
{
Expand All @@ -101,7 +107,7 @@ protected function configureRoutes(RouteCollectionInterface $collection): void
*
* @throws \RuntimeException
*/
protected function configureFormFields(FormMapper $formMapper): void
protected function configureFormFields(FormMapper $form): void
{
$subject = $this->getSubject();

Expand All @@ -110,48 +116,48 @@ protected function configureFormFields(FormMapper $formMapper): void
$nameClasses = 'generic-channel-name input-yt-channelname';
}

$formMapper
$form
->with('Channel')
->add('channelName', TextType::class, [
'label' => 'Channel name',
'attr' => ['class' => $nameClasses],
]);

if (!$subject instanceof PlannedChannelInterface) {
$formMapper->add('streamKey', TextType::class, ['label' => 'Stream key']);
$formMapper->add('streamServer', TextType::class, ['label' => 'Stream server']);
$form->add('streamKey', TextType::class, ['label' => 'Stream key']);
$form->add('streamServer', TextType::class, ['label' => 'Stream server']);
}

if ($subject instanceof ChannelFacebook) {
$formMapper->add('accessToken', HiddenType::class, [
$form->add('accessToken', HiddenType::class, [
'attr' => ['class' => 'fb-access-token'],
]);
$formMapper->add('fbEntityId', HiddenType::class, [
$form->add('fbEntityId', HiddenType::class, [
'attr' => ['class' => 'fb-entity-id'],
]);
}

if ($subject instanceof ChannelYouTube) {
$formMapper->add('youTubeChannelName', TextType::class, [
$form->add('youTubeChannelName', TextType::class, [
'attr' => ['class' => 'input-yt-channelname', 'readonly' => 'readonly'],
]);

$formMapper->add('refreshToken', TextType::class, [
$form->add('refreshToken', TextType::class, [
'attr' => ['class' => 'input-yt-refreshtoken', 'readonly' => 'readonly'],
]);
}

$formMapper->end();
$form->end();
}

/**
* {@inheritdoc}
*
* @throws \RuntimeException
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$datagridMapper
$filter
->add('channelName')
->add('isHealthy');
}
Expand All @@ -161,9 +167,9 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper): voi
*
* @throws \RuntimeException
*/
protected function configureListFields(ListMapper $listMapper): void
protected function configureListFields(ListMapper $list): void
{
$listMapper
$list
->add('channelName')
->add('isHealthy')
->add('_action', 'actions', [
Expand Down
16 changes: 8 additions & 8 deletions Admin/InputAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,36 +37,36 @@ public function __construct(string $code, string $class, string $baseControllerN
* {@inheritdoc}
* @throws \RuntimeException
*/
protected function configureFormFields(FormMapper $formMapper): void
protected function configureFormFields(FormMapper $form): void
{
$subject = $this->getSubject();

$formMapper
$form
->tab('General')
->with('General');

if ($subject instanceof MediaFile) {
$formMapper->add('fileLocation', TextType::class, ['label' => 'File location on server']);
$form->add('fileLocation', TextType::class, ['label' => 'File location on server']);
}

if ($subject instanceof MediaRtmp) {
$formMapper->add('rtmpAddress', TextType::class, ['label' => 'Address of the RTMP stream to repeat']);
$form->add('rtmpAddress', TextType::class, ['label' => 'Address of the RTMP stream to repeat']);
}

if ($subject instanceof MediaUrl) {
$formMapper->add('url', TextType::class, ['label' => 'URL to video file']);
$form->add('url', TextType::class, ['label' => 'URL to video file']);
}

$formMapper->end()
$form->end()
->end();
}

/**
* {@inheritdoc}
* @throws \RuntimeException
*/
protected function configureListFields(ListMapper $listMapper): void
protected function configureListFields(ListMapper $list): void
{
$listMapper->add('__toString', 'string', ['label' => 'Input']);
$list->add('__toString', 'string', ['label' => 'Input']);
}
}
22 changes: 14 additions & 8 deletions Admin/LiveBroadcastAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Sonata\AdminBundle\Form\Type\ModelType;
use Sonata\DoctrineORMAdminBundle\Model\ModelManager;
use Sonata\Form\Type\DateTimePickerType;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\FileType;
Expand All @@ -33,7 +34,12 @@ class LiveBroadcastAdmin extends AbstractAdmin
/**
* @var string
*/
protected $thumbnailPath = '';
protected string $thumbnailPath = '';

/**
* @var array
*/
protected array $datagridValues = [];

/**
* {@inheritdoc}
Expand Down Expand Up @@ -101,12 +107,12 @@ protected function getThumbnailHtml(): ?string
/**
* {@inheritdoc}
*
* @throws \Symfony\Component\DependencyInjection\Exception\InvalidArgumentException
* @throws InvalidArgumentException
* @throws \RuntimeException
*/
protected function configureFormFields(FormMapper $formMapper): void
protected function configureFormFields(FormMapper $form): void
{
$formMapper
$form
->with('General', [
'class' => 'col-md-8',
])
Expand Down Expand Up @@ -165,9 +171,9 @@ protected function configureFormFields(FormMapper $formMapper): void
*
* @throws \RuntimeException
*/
protected function configureDatagridFilters(DatagridMapper $datagridMapper): void
protected function configureDatagridFilters(DatagridMapper $filter): void
{
$datagridMapper
$filter
->add('name')
->add('startTimestamp')
->add('endTimestamp');
Expand All @@ -178,9 +184,9 @@ protected function configureDatagridFilters(DatagridMapper $datagridMapper): voi
*
* @throws \RuntimeException
*/
protected function configureListFields(ListMapper $listMapper): void
protected function configureListFields(ListMapper $list): void
{
$listMapper
$list
->addIdentifier('name')
->add('outputChannels', 'sonata_type_model', ['label' => 'Channel(s)'])
->add('startTimestamp', 'datetime', ['label' => 'Start time'])
Expand Down
Loading

0 comments on commit 9ad6a21

Please sign in to comment.