Skip to content

Commit

Permalink
Converted native enums
Browse files Browse the repository at this point in the history
  • Loading branch information
FelixJacobi committed Jul 26, 2024
1 parent 2dcecde commit cf2ff25
Show file tree
Hide file tree
Showing 12 changed files with 54 additions and 54 deletions.
4 changes: 2 additions & 2 deletions src/BigBlueButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ class BigBlueButton
public function __construct(?string $baseUrl = null, ?string $secret = null, ?TransportInterface $transport = null, HashingAlgorithm $hashingAlgorithm = HashingAlgorithm::SHA_1)
{
if (null === $baseUrl) {
@trigger_error(sprintf('Constructing "%s" without passing a server base URL is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED);
@trigger_error(\sprintf('Constructing "%s" without passing a server base URL is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED);
}

if (null === $secret) {
@trigger_error(sprintf('Constructing "%s" without passing a secret is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED);
@trigger_error(\sprintf('Constructing "%s" without passing a secret is deprecated and will throw an exception 6.0.', self::class), \E_USER_DEPRECATED);
}

if (getenv('BBB_SECURITY_SALT') !== false || getenv('BBB_SECRET') !== false) {
Expand Down
38 changes: 19 additions & 19 deletions src/Enum/ApiMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,24 @@
/**
* @psalm-immutable
*/
class ApiMethod extends Enum
enum ApiMethod: string
{
public const CREATE = 'create';
public const JOIN = 'join';
public const ENTER = 'enter';
public const END = 'end';
public const IS_MEETING_RUNNING = 'isMeetingRunning';
public const GET_MEETING_INFO = 'getMeetingInfo';
public const GET_MEETINGS = 'getMeetings';
public const SIGN_OUT = 'signOut';
public const GET_RECORDINGS = 'getRecordings';
public const PUBLISH_RECORDINGS = 'publishRecordings';
public const DELETE_RECORDINGS = 'deleteRecordings';
public const UPDATE_RECORDINGS = 'updateRecordings';
public const GET_RECORDING_TEXT_TRACKS = 'getRecordingTextTracks';
public const PUT_RECORDING_TEXT_TRACK = 'putRecordingTextTrack';
public const HOOKS_CREATE = 'hooks/create';
public const HOOKS_LIST = 'hooks/list';
public const HOOKS_DESTROY = 'hooks/destroy';
public const INSERT_DOCUMENT = 'insertDocument';
case CREATE = 'create';
case JOIN = 'join';
case ENTER = 'enter';
case END = 'end';
case IS_MEETING_RUNNING = 'isMeetingRunning';
case GET_MEETING_INFO = 'getMeetingInfo';
case GET_MEETINGS = 'getMeetings';
case SIGN_OUT = 'signOut';
case GET_RECORDINGS = 'getRecordings';
case PUBLISH_RECORDINGS = 'publishRecordings';
case DELETE_RECORDINGS = 'deleteRecordings';
case UPDATE_RECORDINGS = 'updateRecordings';
case GET_RECORDING_TEXT_TRACKS = 'getRecordingTextTracks';
case PUT_RECORDING_TEXT_TRACK = 'putRecordingTextTrack';
case HOOKS_CREATE = 'hooks/create';
case HOOKS_LIST = 'hooks/list';
case HOOKS_DESTROY = 'hooks/destroy';
case INSERT_DOCUMENT = 'insertDocument';
}
10 changes: 5 additions & 5 deletions src/Enum/GuestPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
/**
* @psalm-immutable
*/
class GuestPolicy extends Enum
enum GuestPolicy: string
{
public const ALWAYS_ACCEPT = 'ALWAYS_ACCEPT';
public const ALWAYS_DENY = 'ALWAYS_DENY';
public const ASK_MODERATOR = 'ASK_MODERATOR';
public const ALWAYS_ACCEPT_AUTH = 'ALWAYS_ACCEPT_AUTH';
case ALWAYS_ACCEPT = 'ALWAYS_ACCEPT';
case ALWAYS_DENY = 'ALWAYS_DENY';
case ASK_MODERATOR = 'ASK_MODERATOR';
case ALWAYS_ACCEPT_AUTH = 'ALWAYS_ACCEPT_AUTH';
}
10 changes: 5 additions & 5 deletions src/Enum/MeetingLayout.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
/**
* @psalm-immutable
*/
class MeetingLayout extends Enum
enum MeetingLayout: string
{
public const CUSTOM_LAYOUT = 'CUSTOM_LAYOUT';
public const SMART_LAYOUT = 'SMART_LAYOUT';
public const PRESENTATION_FOCUS = 'PRESENTATION_FOCUS';
public const VIDEO_FOCUS = 'VIDEO_FOCUS';
case CUSTOM_LAYOUT = 'CUSTOM_LAYOUT';
case SMART_LAYOUT = 'SMART_LAYOUT';
case PRESENTATION_FOCUS = 'PRESENTATION_FOCUS';
case VIDEO_FOCUS = 'VIDEO_FOCUS';
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

// @codeCoverageIgnoreStart
if (!interface_exists(ClientInterface::class)) {
throw new \LogicException(sprintf(
throw new \LogicException(\sprintf(
'The "%s" interface was not found. '.
'You cannot use "%s" without it.'.
'Try running "composer require" for a package which provides psr/http-client-implementation.',
Expand All @@ -44,7 +44,7 @@
}

if (!interface_exists(RequestFactoryInterface::class)) {
throw new \LogicException(sprintf(
throw new \LogicException(\sprintf(
'The "%s" interface was not found. '.
'You cannot use "%s" without it.'.
'Try running "composer require" for a package which provides psr/http-factory-implementation.',
Expand All @@ -54,7 +54,7 @@
}

if (!interface_exists(StreamFactoryInterface::class)) {
throw new \LogicException(sprintf(
throw new \LogicException(\sprintf(
'The "%s" interface was not found. '.
'You cannot use "%s" without it.'.
'Try running "composer require" for a package which provides psr/http-factory-implementation.',
Expand Down Expand Up @@ -121,7 +121,7 @@ public function request(TransportRequest $request): TransportResponse
try {
$psrResponse = $this->httpClient->sendRequest($psrRequest);
} catch (ClientExceptionInterface $e) {
throw new RuntimeException(sprintf('HTTP request failed: %s', $e->getMessage()), 0, $e);
throw new RuntimeException(\sprintf('HTTP request failed: %s', $e->getMessage()), 0, $e);
}

if ($psrResponse->getStatusCode() < 200 || $psrResponse->getStatusCode() >= 300) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

// @codeCoverageIgnoreStart
if (!interface_exists(HttpClientInterface::class)) {
throw new \LogicException(sprintf(
throw new \LogicException(\sprintf(
'The "%s" interface was not found. '.
'You cannot use "%s" without it.'.
'Try running "composer require" for a package which provides symfony/http-client-implementation.',
Expand Down Expand Up @@ -89,7 +89,7 @@ public static function create(array $defaultHeaders = [], array $defaultOptions
{
// @codeCoverageIgnoreStart
if (!class_exists(HttpClient::class)) {
throw new \LogicException(sprintf(
throw new \LogicException(\sprintf(
'Cannot create an instance of "%s" when Symfony HttpClient is not installed. '.
'Either instantiate the class by yourself and pass a proper implementation or '.
'try to run "composer require symfony/http-client".',
Expand Down Expand Up @@ -131,7 +131,7 @@ public function request(TransportRequest $request): TransportResponse

return new TransportResponse($symfonyResponse->getContent(), self::extractJsessionCookie($symfonyResponse));
} catch (TransportExceptionInterface $e) {
throw new RuntimeException(sprintf('HTTP request failed: %s', $e->getMessage()), 0, $e);
throw new RuntimeException(\sprintf('HTTP request failed: %s', $e->getMessage()), 0, $e);
} catch (ClientExceptionInterface|RedirectionExceptionInterface|ServerExceptionInterface $e) {
throw new NetworkException('Bad response.', $e->getCode(), $e);
}
Expand Down
6 changes: 3 additions & 3 deletions src/Http/Transport/CurlTransport.php
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ private static function getHeadersAndContentFromCurlHandle($curlHandle): array
// @codeCoverageIgnoreStart
if (\PHP_VERSION_ID >= 80000 && !$curlHandle instanceof \CurlHandle) {
/* @noinspection PhpElementIsNotAvailableInCurrentPhpVersionInspection */
throw new \InvalidArgumentException(sprintf('$curlHandle must be "%s". "%s" given.', \CurlHandle::class, get_debug_type($curlHandle)));
throw new \InvalidArgumentException(\sprintf('$curlHandle must be "%s". "%s" given.', \CurlHandle::class, get_debug_type($curlHandle)));
} elseif (\PHP_VERSION_ID < 80000 && !\is_resource($curlHandle)) {
throw new \InvalidArgumentException(sprintf('$curlHandle must be resource. "%s" given.', \is_object($curlHandle) ? \get_class($curlHandle) : \gettype($curlHandle)));
throw new \InvalidArgumentException(\sprintf('$curlHandle must be resource. "%s" given.', \is_object($curlHandle) ? \get_class($curlHandle) : \gettype($curlHandle)));
}
// @codeCoverageIgnoreEnd

Expand Down Expand Up @@ -231,7 +231,7 @@ private static function getHeadersAndContentFromCurlHandle($curlHandle): array
$splitHeader = explode(': ', $line, 2);
// @codeCoverageIgnoreStart
if (!isset($splitHeader[0], $splitHeader[1])) {
throw new \InvalidArgumentException(sprintf('Header value "%s" is invalid. Expected format is "Header-Name: value".', $line));
throw new \InvalidArgumentException(\sprintf('Header value "%s" is invalid. Expected format is "Header-Name: value".', $line));
}
// @codeCoverageIgnoreEnd

Expand Down
6 changes: 3 additions & 3 deletions src/Http/Transport/Header.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ public static function mergeCurlHeaders(array ...$headers): array
foreach ($headers as $headerSet) {
foreach ($headerSet as $header) {
if (!\is_string($header)) {
throw new \InvalidArgumentException(sprintf(
throw new \InvalidArgumentException(\sprintf(
'Non-string header with type "%s" passed.',
\is_object($header) ? \get_class($header) : \gettype($header)
));
}

$splitHeader = explode(': ', $header, 2);
if (!isset($splitHeader[0], $splitHeader[1])) {
throw new \InvalidArgumentException(sprintf('Header value "%s" is invalid. Expected format is "Header-Name: value".', $header));
throw new \InvalidArgumentException(\sprintf('Header value "%s" is invalid. Expected format is "Header-Name: value".', $header));
}

// Enforce lower case for header names to avoid duplicates in mixed case. The case of header names should
Expand All @@ -62,7 +62,7 @@ public static function mergeCurlHeaders(array ...$headers): array

$result = [];
foreach ($mergedHeaders as $header => $value) {
$result[] = sprintf('%s: %s', $header, $value);
$result[] = \sprintf('%s: %s', $header, $value);
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Parameters/CreateMeetingParameters.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

namespace BigBlueButton\Parameters;

use BigBlueButton\Enum\GuestPolicy;
use BigBlueButton\Enum\Feature;
use BigBlueButton\Enum\GuestPolicy;

/**
* @method string getName()
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/AbstractBigBlueButtonFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public function testJoinMeeting()
$params = $this->generateJoinMeetingParams();
$joinMeetingParams = new JoinMeetingParameters($result->getMeetingId(), $params['fullName'], $params['role']);
$joinMeetingParams->setRedirect(false);
$joinMeetingParams->setCreateTime(sprintf('%.0f', $creationTime));
$joinMeetingParams->setCreateTime(\sprintf('%.0f', $creationTime));

$joinMeeting = $this->bbb->joinMeeting($joinMeetingParams);
$this->assertEquals('SUCCESS', $joinMeeting->getReturnCode(), 'Join meeting');
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/Http/Transport/HeaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function provideBadlyFormattedHeaders(): iterable
public function testMergeCurlHeadersWithBadHeaders(string $badHeader): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf('Header value "%s" is invalid. Expected format is "Header-Name: value".', $badHeader));
$this->expectExceptionMessage(\sprintf('Header value "%s" is invalid. Expected format is "Header-Name: value".', $badHeader));

Header::mergeCurlHeaders([$badHeader]);
}
Expand All @@ -82,7 +82,7 @@ public function provideNonStringHeaders(): iterable
public function testMergeCurlHeadersWithNonStringHeaders($badHeader): void
{
$this->expectException(\InvalidArgumentException::class);
$this->expectExceptionMessage(sprintf(
$this->expectExceptionMessage(\sprintf(
'Non-string header with type "%s" passed.',
\is_object($badHeader) ? \get_class($badHeader) : \gettype($badHeader)
));
Expand Down
12 changes: 6 additions & 6 deletions tests/unit/Responses/GetRecordingsTextTracksResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ public function testGetRecordingTextTracksResponseTypes()
$secondTracks = $this->tracks->getTracks()[1];

$this->assertEachGetterValueIsString($secondTracks, [
'getHref',
'getKind',
'getLabel',
'getLang',
'getSource',
]
'getHref',
'getKind',
'getLabel',
'getLang',
'getSource',
]
);
}

Expand Down

0 comments on commit cf2ff25

Please sign in to comment.