Skip to content

Commit

Permalink
Const to PascalCase
Browse files Browse the repository at this point in the history
  • Loading branch information
stanislav-janu committed Oct 4, 2023
1 parent 2f6a811 commit 9ed23f3
Show file tree
Hide file tree
Showing 10 changed files with 41 additions and 56 deletions.
6 changes: 3 additions & 3 deletions src/Authentication/OAuth2Client.php
Expand Up @@ -37,7 +37,7 @@ class OAuth2Client
/**
* @const string The base authorization URL.
*/
final public const BASE_AUTHORIZATION_URL = 'https://www.facebook.com';
final public const BaseAuthorizationUrl = 'https://www.facebook.com';

/**
* The last request sent to Graph.
Expand Down Expand Up @@ -117,12 +117,12 @@ public function getAuthorizationUrl(
'client_id' => $this->application->getId(),
'state' => $state,
'response_type' => 'code',
'sdk' => 'php-sdk-' . Facebook::VERSION,
'sdk' => 'php-sdk-' . Facebook::Version,
'redirect_uri' => $redirectUrl,
'scope' => implode(',', $scope),
];

return static::BASE_AUTHORIZATION_URL . '/' . $this->graphVersion . '/dialog/oauth?' . http_build_query($params, '', $separator);
return static::BaseAuthorizationUrl . '/' . $this->graphVersion . '/dialog/oauth?' . http_build_query($params, '', $separator);
}


Expand Down
29 changes: 7 additions & 22 deletions src/Client.php
Expand Up @@ -35,37 +35,22 @@ class Client
/**
* @const string Production Graph API URL.
*/
final public const BASE_GRAPH_URL = 'https://graph.facebook.com';
final public const BaseGraphUrl = 'https://graph.facebook.com';

/**
* @const string Graph API URL for video uploads.
*/
final public const BASE_GRAPH_VIDEO_URL = 'https://graph-video.facebook.com';
final public const BaseGraphVideoUrl = 'https://graph-video.facebook.com';

/**
* @const string Beta Graph API URL.
*/
final public const BASE_GRAPH_URL_BETA = 'https://graph.beta.facebook.com';
final public const BaseGraphUrlBeta = 'https://graph.beta.facebook.com';

/**
* @const string Beta Graph API URL for video uploads.
*/
final public const BASE_GRAPH_VIDEO_URL_BETA = 'https://graph-video.beta.facebook.com';

/**
* @const int The timeout in seconds for a normal request.
*/
final public const DEFAULT_REQUEST_TIMEOUT = 60;

/**
* @const int The timeout in seconds for a request that contains file uploads.
*/
final public const DEFAULT_FILE_UPLOAD_REQUEST_TIMEOUT = 3600;

/**
* @const int The timeout in seconds for a request that contains video uploads.
*/
final public const DEFAULT_VIDEO_UPLOAD_REQUEST_TIMEOUT = 7200;
final public const BaseGraphVideoUrlBeta = 'https://graph-video.beta.facebook.com';

public static int $requestCount = 0;

Expand Down Expand Up @@ -119,11 +104,11 @@ public function getBaseGraphUrl(bool $postToVideoUrl = false): string
{
if ($postToVideoUrl) {
return $this->enableBetaMode
? static::BASE_GRAPH_VIDEO_URL_BETA
: static::BASE_GRAPH_VIDEO_URL;
? static::BaseGraphVideoUrlBeta
: static::BaseGraphVideoUrl;
}

return $this->enableBetaMode ? static::BASE_GRAPH_URL_BETA : static::BASE_GRAPH_URL;
return $this->enableBetaMode ? static::BaseGraphUrlBeta : static::BaseGraphUrl;
}


Expand Down
14 changes: 7 additions & 7 deletions src/Facebook.php
Expand Up @@ -49,17 +49,17 @@ class Facebook
/**
* @const string Version number of the Facebook PHP SDK.
*/
final public const VERSION = '0.1';
final public const Version = '0.1';

/**
* @const string The name of the environment variable that contains the app ID.
*/
final public const APP_ID_ENV_NAME = 'FACEBOOK_APP_ID';
final public const AppIdEnvName = 'FACEBOOK_APP_ID';
/**
* @const string The name of the environment variable that contains the app secret.
*/
final public const APP_SECRET_ENV_NAME = 'FACEBOOK_APP_SECRET';
final public const AppSecretEnvName = 'FACEBOOK_APP_SECRET';

/**
* The Application entity
Expand Down Expand Up @@ -109,8 +109,8 @@ class Facebook
public function __construct(array $config = [])
{
$config = array_merge([
'app_id' => getenv(static::APP_ID_ENV_NAME),
'app_secret' => getenv(static::APP_SECRET_ENV_NAME),
'app_id' => getenv(static::AppIdEnvName),
'app_secret' => getenv(static::AppSecretEnvName),
'default_graph_version' => null,
'enable_beta_mode' => false,
'http_client' => null,
Expand All @@ -119,10 +119,10 @@ public function __construct(array $config = [])
], $config);

if (!$config['app_id']) {
throw new SDKException('Required "app_id" key not supplied in config and could not find fallback environment variable "' . static::APP_ID_ENV_NAME . '"');
throw new SDKException('Required "app_id" key not supplied in config and could not find fallback environment variable "' . static::AppIdEnvName . '"');
}
if (!$config['app_secret']) {
throw new SDKException('Required "app_secret" key not supplied in config and could not find fallback environment variable "' . static::APP_SECRET_ENV_NAME . '"');
throw new SDKException('Required "app_secret" key not supplied in config and could not find fallback environment variable "' . static::AppSecretEnvName . '"');
}
if ($config['http_client'] !== null && !$config['http_client'] instanceof ClientInterface) {
throw new InvalidArgumentException('Required "http_client" key to be null or an instance of \Psr\Http\Client\ClientInterface');
Expand Down
16 changes: 8 additions & 8 deletions src/GraphNode/GraphNodeFactory.php
Expand Up @@ -42,17 +42,17 @@ class GraphNodeFactory
/**
* @const string The base graph object class.
*/
final public const BASE_GRAPH_NODE_CLASS = GraphNode::class;
final public const BaseGraphNodeClass = GraphNode::class;

/**
* @const string The base graph edge class.
*/
final public const BASE_GRAPH_EDGE_CLASS = GraphEdge::class;
final public const BaseGraphEdgeClass = GraphEdge::class;

/**
* @const string The graph object prefix.
*/
final public const BASE_GRAPH_OBJECT_PREFIX = '\JanuSoftware\Facebook\GraphNode\\';
final public const BaseGraphObjectPrefix = '\JanuSoftware\Facebook\GraphNode\\';

/**
* The decoded body of the Response entity from Graph
Expand Down Expand Up @@ -102,7 +102,7 @@ public function makeGraphEdge(string $subclassName = null, bool $auto_prefix = t
$this->validateResponseCastableAsGraphEdge();

if ($subclassName !== null && $auto_prefix) {
$subclassName = static::BASE_GRAPH_OBJECT_PREFIX . $subclassName;
$subclassName = static::BaseGraphObjectPrefix . $subclassName;
}

return $this->castAsGraphNodeOrGraphEdge($this->decodedBody, $subclassName);
Expand Down Expand Up @@ -143,7 +143,7 @@ public function validateResponseCastableAsGraphEdge(): void
*/
public function safelyMakeGraphNode(array $data, string $subclassName = null): GraphNode
{
$subclassName ??= static::BASE_GRAPH_NODE_CLASS;
$subclassName ??= static::BaseGraphNodeClass;
static::validateSubclass($subclassName);

// Remember the parent node ID
Expand Down Expand Up @@ -234,7 +234,7 @@ public function safelyMakeGraphEdge(
$parentGraphEdgeEndpoint = $parentNodeId !== null && $parentKey !== null
? '/' . $parentNodeId . '/' . $parentKey
: null;
$className = static::BASE_GRAPH_EDGE_CLASS;
$className = static::BaseGraphEdgeClass;

return new $className($this->response->getRequest(), $dataList, $metaData, $parentGraphEdgeEndpoint, $subclassName);
}
Expand Down Expand Up @@ -278,8 +278,8 @@ public static function isCastableAsGraphEdge(array $data): bool
public static function validateSubclass(string $subclassName): void
{
if (
$subclassName == static::BASE_GRAPH_NODE_CLASS
|| is_subclass_of($subclassName, static::BASE_GRAPH_NODE_CLASS)
$subclassName == static::BaseGraphNodeClass
|| is_subclass_of($subclassName, static::BaseGraphNodeClass)
) {
return;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Helper/RedirectLoginHelper.php
Expand Up @@ -37,7 +37,7 @@ class RedirectLoginHelper
/**
* @const int The length of CSRF string to validate the login link.
*/
final public const CSRF_LENGTH = 32;
final public const CsrfLength = 32;

protected UrlDetectionInterface $urlDetectionHandler;
protected PersistentDataInterface $persistentDataHandler;
Expand Down Expand Up @@ -95,7 +95,7 @@ private function makeUrl(string $redirectUrl, array $scope, array $params = [],

private function getPseudoRandomString(): string
{
return bin2hex(random_bytes(static::CSRF_LENGTH));
return bin2hex(random_bytes(static::CsrfLength));
}


Expand Down
2 changes: 1 addition & 1 deletion src/Request.php
Expand Up @@ -467,7 +467,7 @@ public function getUrl(): string
public static function getDefaultHeaders(): array
{
return [
'User-Agent' => 'fb-php-' . Facebook::VERSION,
'User-Agent' => 'fb-php-' . Facebook::Version,
'Accept-Encoding' => '*',
];
}
Expand Down
2 changes: 1 addition & 1 deletion tests/Authentication/OAuth2ClientTest.php
Expand Up @@ -88,7 +88,7 @@ public function testCanBuildAuthorizationUrl(): void
'client_id' => '123',
'redirect_uri' => 'https://foo.bar',
'state' => 'foo_state',
'sdk' => 'php-sdk-' . Facebook::VERSION,
'sdk' => 'php-sdk-' . Facebook::Version,
'scope' => implode(',', $scope),
'foo' => 'bar',
];
Expand Down
14 changes: 7 additions & 7 deletions tests/ClientTest.php
Expand Up @@ -79,11 +79,11 @@ public function testBetaModeCanBeDisabledOrEnabledViaConstructor(): void
{
$client = new Client(null, false);
$url = $client->getBaseGraphUrl();
$this->assertEquals(Client::BASE_GRAPH_URL, $url);
$this->assertEquals(Client::BaseGraphUrl, $url);

$client = new Client(null, true);
$url = $client->getBaseGraphUrl();
$this->assertEquals(Client::BASE_GRAPH_URL_BETA, $url);
$this->assertEquals(Client::BaseGraphUrlBeta, $url);
}


Expand All @@ -92,11 +92,11 @@ public function testBetaModeCanBeDisabledOrEnabledViaMethod(): void
$client = new Client;
$client->enableBetaMode(false);
$url = $client->getBaseGraphUrl();
$this->assertEquals(Client::BASE_GRAPH_URL, $url);
$this->assertEquals(Client::BaseGraphUrl, $url);

$client->enableBetaMode(true);
$url = $client->getBaseGraphUrl();
$this->assertEquals(Client::BASE_GRAPH_URL_BETA, $url);
$this->assertEquals(Client::BaseGraphUrlBeta, $url);
}


Expand All @@ -105,11 +105,11 @@ public function testGraphVideoUrlCanBeSet(): void
$client = new Client;
$client->enableBetaMode(false);
$url = $client->getBaseGraphUrl($postToVideoUrl = true);
$this->assertEquals(Client::BASE_GRAPH_VIDEO_URL, $url);
$this->assertEquals(Client::BaseGraphVideoUrl, $url);

$client->enableBetaMode(true);
$url = $client->getBaseGraphUrl($postToVideoUrl = true);
$this->assertEquals(Client::BASE_GRAPH_VIDEO_URL_BETA, $url);
$this->assertEquals(Client::BaseGraphVideoUrlBeta, $url);
}


Expand Down Expand Up @@ -160,7 +160,7 @@ public function testABatchRequestWillProperlyBatchFiles(): void

$body = $body?->getContents() ?? '';

$this->assertEquals(Client::BASE_GRAPH_VIDEO_URL, $url);
$this->assertEquals(Client::BaseGraphVideoUrl, $url);
$this->assertEquals('POST', $method);
$this->assertStringContainsString('multipart/form-data; boundary=', $headers['Content-Type']);
$this->assertStringContainsString('Content-Disposition: form-data; name="batch"', $body);
Expand Down
8 changes: 4 additions & 4 deletions tests/FacebookTest.php
Expand Up @@ -59,7 +59,7 @@ public function testInstantiatingWithoutAppIdThrows(): void
{
$this->expectException(SDKException::class);
// unset value so there is no fallback to test expected Exception
putenv(Facebook::APP_ID_ENV_NAME . '=');
putenv(Facebook::AppIdEnvName . '=');
$config = [
'app_secret' => 'foo_secret',
'default_graph_version' => 'v0.0',
Expand All @@ -72,7 +72,7 @@ public function testInstantiatingWithoutAppSecretThrows(): void
{
$this->expectException(SDKException::class);
// unset value so there is no fallback to test expected Exception
putenv(Facebook::APP_SECRET_ENV_NAME . '=');
putenv(Facebook::AppSecretEnvName . '=');
$config = [
'app_id' => 'foo_id',
'default_graph_version' => 'v0.0',
Expand Down Expand Up @@ -200,7 +200,7 @@ public function testCreatingANewRequestWillDefaultToTheProperConfig(): void
$this->assertEquals('v1337', $fb->getDefaultGraphVersion());
$this->assertEquals('v1337', $request->getGraphVersion());
$this->assertEquals(
Client::BASE_GRAPH_URL_BETA,
Client::BaseGraphUrlBeta,
$fb->getClient()->getBaseGraphUrl(),
);
}
Expand All @@ -221,7 +221,7 @@ public function testCreatingANewBatchRequestWillDefaultToTheProperConfig(): void
$this->assertEquals('foo_token', (string) $batchRequest->getAccessToken());
$this->assertEquals('v1337', $batchRequest->getGraphVersion());
$this->assertEquals(
Client::BASE_GRAPH_URL_BETA,
Client::BaseGraphUrlBeta,
$fb->getClient()->getBaseGraphUrl(),
);
$this->assertInstanceOf('JanuSoftware\Facebook\BatchRequest', $batchRequest);
Expand Down
2 changes: 1 addition & 1 deletion tests/Helper/RedirectLoginHelperTest.php
Expand Up @@ -63,7 +63,7 @@ public function testLoginURL(): void
'client_id' => '123',
'redirect_uri' => self::REDIRECT_URL,
'state' => $this->persistentDataHandler->get('state'),
'sdk' => 'php-sdk-' . Facebook::VERSION,
'sdk' => 'php-sdk-' . Facebook::Version,
'scope' => implode(',', $scope),
];
foreach ($params as $key => $value) {
Expand Down

0 comments on commit 9ed23f3

Please sign in to comment.