Skip to content

Commit

Permalink
ENH Use class name instead of self
Browse files Browse the repository at this point in the history
  • Loading branch information
emteknetnz committed Jun 14, 2024
1 parent 56e9886 commit 1f32e33
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 25 deletions.
4 changes: 2 additions & 2 deletions code/Forms/AssetFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public function getForm(RequestHandler $controller = null, $name = FormFactory::
$form->loadDataFrom($record);

// Mark as readonly for some types
if ($this->getFormType($context) === self::TYPE_ADMIN && !$record->canEdit()) {
if ($this->getFormType($context) === AssetFormFactory::TYPE_ADMIN && !$record->canEdit()) {
$form->makeReadonly();
}
}
Expand Down Expand Up @@ -242,7 +242,7 @@ protected function getFormFields(RequestHandler $controller = null, $formName, $
->setRecordID($record->ID)
->addExtraClass('editor__file-preview');

if ($this->getFormType($context) !== self::TYPE_ADMIN) {
if ($this->getFormType($context) !== AssetFormFactory::TYPE_ADMIN) {
$previewField->performReadonlyTransformation();
}

Expand Down
2 changes: 1 addition & 1 deletion code/Forms/MoveFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class MoveFormFactory implements FormFactory
{
use Extensible;

public function getForm(RequestHandler $controller = null, $name = self::DEFAULT_NAME, $context = [])
public function getForm(RequestHandler $controller = null, $name = MoveFormFactory::DEFAULT_NAME, $context = [])
{
$form = Form::create(
$controller,
Expand Down
14 changes: 7 additions & 7 deletions code/Forms/RemoteFileFormFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class RemoteFileFormFactory implements FormFactory
* @param array $context
* @return Form
*/
public function getForm(RequestHandler $controller = null, $name = self::DEFAULT_NAME, $context = [])
public function getForm(RequestHandler $controller = null, $name = RemoteFileFormFactory::DEFAULT_NAME, $context = [])
{
// Allow form to be disabled
if (!static::config()->get('enabled')) {
Expand Down Expand Up @@ -316,8 +316,8 @@ protected function getEditFormFields($context)
protected function validateURLScheme($url)
{
$scheme = strtolower(parse_url($url ?? '', PHP_URL_SCHEME) ?? '');
$allowedSchemes = self::config()->get('fileurl_scheme_whitelist');
$disallowedSchemes = self::config()->get('fileurl_scheme_blacklist');
$allowedSchemes = static::config()->get('fileurl_scheme_whitelist');
$disallowedSchemes = static::config()->get('fileurl_scheme_blacklist');
if (!$scheme
|| ($allowedSchemes && !in_array($scheme, $allowedSchemes ?? []))
|| ($disallowedSchemes && in_array($scheme, $disallowedSchemes ?? []))
Expand All @@ -336,8 +336,8 @@ protected function validateURLScheme($url)
protected function validateURLHost($url)
{
$domain = strtolower(parse_url($url ?? '', PHP_URL_HOST) ?? '');
$allowedDomains = self::config()->get('fileurl_domain_whitelist');
$disallowedDomains = self::config()->get('fileurl_domain_blacklist');
$allowedDomains = static::config()->get('fileurl_domain_whitelist');
$disallowedDomains = static::config()->get('fileurl_domain_blacklist');
if (!$domain
|| ($allowedDomains && !in_array($domain, $allowedDomains ?? []))
|| ($disallowedDomains && in_array($domain, $disallowedDomains ?? []))
Expand All @@ -359,8 +359,8 @@ protected function validateURLPort($url)
if (!$port) {
return;
}
$allowedPorts = self::config()->get('fileurl_port_whitelist');
$disallowedPorts = self::config()->get('fileurl_port_blacklist');
$allowedPorts = static::config()->get('fileurl_port_whitelist');
$disallowedPorts = static::config()->get('fileurl_port_blacklist');
if (($allowedPorts && !in_array($port, $allowedPorts ?? []))
|| ($disallowedPorts && in_array($port, $disallowedPorts ?? []))
) {
Expand Down
12 changes: 6 additions & 6 deletions code/GraphQL/Resolvers/PublicationResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ class PublicationResolver

public static function resolvePublishFiles(...$params)
{
return self::resolvePublicationOperation(self::ACTION_PUBLISH, ...$params);
return PublicationResolver::resolvePublicationOperation(PublicationResolver::ACTION_PUBLISH, ...$params);
}

public static function resolveUnpublishFiles(...$params)
{
return self::resolvePublicationOperation(self::ACTION_UNPUBLISH, ...$params);
return PublicationResolver::resolvePublicationOperation(PublicationResolver::ACTION_UNPUBLISH, ...$params);
}

/**
Expand All @@ -45,7 +45,7 @@ private static function resolvePublicationOperation(
if (!isset($args['ids']) || !is_array($args['ids'])) {
throw new InvalidArgumentException('IDs must be an array');
}
$isPublish = $action === self::ACTION_PUBLISH;
$isPublish = $action === PublicationResolver::ACTION_PUBLISH;
$sourceStage = $isPublish ? Versioned::DRAFT : Versioned::LIVE;
$force = $args['force'] ?? false;
$quiet = $args['quiet'] ?? false;
Expand Down Expand Up @@ -87,8 +87,8 @@ private static function resolvePublicationOperation(

foreach ($allowedFiles as $file) {
$result[] = $isPublish
? self::publishFile($file, $force)
: self::unpublishFile($file, $force);
? PublicationResolver::publishFile($file, $force)
: PublicationResolver::unpublishFile($file, $force);
}

return $result;
Expand Down Expand Up @@ -116,7 +116,7 @@ private static function unpublishFile(File $file, $force = false)
{
// If not forcing, make sure we aren't interfering with any owners
if (!$force) {
$ownersCount = self::countLiveOwners($file);
$ownersCount = PublicationResolver::countLiveOwners($file);
if ($ownersCount) {
return new Notice(
_t(
Expand Down
8 changes: 4 additions & 4 deletions code/Model/ThumbnailGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ class ThumbnailGenerator
* @var array
*/
private static $thumbnail_links = [
AssetStore::VISIBILITY_PROTECTED => self::INLINE,
AssetStore::VISIBILITY_PUBLIC => self::URL,
AssetStore::VISIBILITY_PROTECTED => ThumbnailGenerator::INLINE,
AssetStore::VISIBILITY_PUBLIC => ThumbnailGenerator::URL,
];

/**
Expand Down Expand Up @@ -141,9 +141,9 @@ public function generateLink(AssetContainer $thumbnail = null)

// Build thumbnail
switch ($urlRule) {
case self::URL:
case ThumbnailGenerator::URL:
return $thumbnail->getURL();
case self::INLINE:
case ThumbnailGenerator::INLINE:
// Generate inline content
$base64 = base64_encode($thumbnail->getString() ?? '');
return sprintf(
Expand Down
8 changes: 4 additions & 4 deletions tests/php/Forms/FileFormBuilderTest/FileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,21 @@ class FileExtension extends DataExtension implements TestOnly

public function canDelete($member)
{
return self::$canDelete;
return FileExtension::$canDelete;
}

public function canPublish($member = null)
{
return self::$canPublish;
return FileExtension::$canPublish;
}

public function canUnpublish($member = null)
{
return self::$canUnpublish;
return FileExtension::$canUnpublish;
}

public function canEdit($member = null)
{
return self::$canEdit;
return FileExtension::$canEdit;
}
}
2 changes: 1 addition & 1 deletion tests/php/Forms/RemoteFileFormFactoryTest/MockEmbed.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function getOptions()

/**
* @param array $options
* @return self
* @return MockEmbed
*/
public function setOptions(array $options)
{
Expand Down

0 comments on commit 1f32e33

Please sign in to comment.