Skip to content

Commit

Permalink
Merge pull request #590 from creative-commoners/pulls/5.2/remove-self
Browse files Browse the repository at this point in the history
ENH Use class name instead of self
  • Loading branch information
GuySartorelli authored Jun 17, 2024
2 parents 34eb185 + fb18d9d commit 80bdc3b
Show file tree
Hide file tree
Showing 66 changed files with 232 additions and 232 deletions.
6 changes: 3 additions & 3 deletions src/Config/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ private function path($path, callable $callback): void
* @return $this
* @throws SchemaBuilderException
*/
public function set($path, $value): self
public function set($path, $value): Configuration
{
$this->path($path, function (&$scope, $part) use ($value) {
$scope[$part] = $value;
Expand All @@ -100,7 +100,7 @@ public function set($path, $value): self
* @return $this
* @throws SchemaBuilderException
*/
public function unset($path): self
public function unset($path): Configuration
{
$this->path($path, function (&$scope, $part) {
unset($scope[$part]);
Expand All @@ -113,7 +113,7 @@ public function unset($path): self
* @param array $settings
* @return $this
*/
public function apply(array $settings): self
public function apply(array $settings): Configuration
{
$this->settings = Priority::mergeArray($settings, $this->settings);

Expand Down
8 changes: 4 additions & 4 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ public function getMergedCorsConfig(): array
return array_merge($defaults, $override);
}

public function setCorsConfig(array $config): self
public function setCorsConfig(array $config): Controller
{
$this->corsConfig = array_merge($this->corsConfig, $config);

Expand Down Expand Up @@ -326,7 +326,7 @@ protected function getRequestOrigin(HTTPRequest $request): ?string
protected function handleOptions(HTTPRequest $request): HTTPResponse
{
$response = HTTPResponse::create();
$corsConfig = Config::inst()->get(self::class, 'cors');
$corsConfig = Config::inst()->get(Controller::class, 'cors');
if ($corsConfig['Enabled']) {
// CORS config is enabled and the request is an OPTIONS pre-flight.
// Process the CORS config and add appropriate headers.
Expand Down Expand Up @@ -390,7 +390,7 @@ protected function getRequestUser(HTTPRequest $request): ?Member
return $member;
}

public function setSchemaKey(string $schemaKey): self
public function setSchemaKey(string $schemaKey): Controller
{
$this->schemaKey = $schemaKey;
return $this;
Expand All @@ -406,7 +406,7 @@ public function getQueryHandler(): QueryHandlerInterface
return $this->queryHandler;
}

public function setQueryHandler(QueryHandlerInterface $queryHandler): self
public function setQueryHandler(QueryHandlerInterface $queryHandler): Controller
{
$this->queryHandler = $queryHandler;
return $this;
Expand Down
8 changes: 4 additions & 4 deletions src/Dev/Benchmark.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ class Benchmark

public static function start(string $id): void
{
if (isset(self::$benchmarks[$id])) {
if (isset(Benchmark::$benchmarks[$id])) {
throw new \Exception(sprintf('Benchmark ID %s has already started', $id));
}
self::$benchmarks[$id] = microtime(true);
Benchmark::$benchmarks[$id] = microtime(true);
}

/**
Expand All @@ -31,7 +31,7 @@ public static function start(string $id): void
*/
public static function end(string $id, string $message = null, bool $return = true): ?string
{
$benchmark = self::$benchmarks[$id] ?? null;
$benchmark = Benchmark::$benchmarks[$id] ?? null;
if (!$benchmark) {
throw new \Exception(sprintf('Benchmark ID %s was never started', $id));
}
Expand All @@ -40,7 +40,7 @@ public static function end(string $id, string $message = null, bool $return = tr
$ms = $rounded * 1000;

$result = $message ? sprintf($message, $ms) : sprintf('[%s]: %sms', $id, $ms);
unset(self::$benchmarks[$id]);
unset(Benchmark::$benchmarks[$id]);

if ($return) {
return $result;
Expand Down
4 changes: 2 additions & 2 deletions src/Dev/DevelopmentAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function index(HTTPRequest $request)

echo '<div class="options"><ul>';
$evenOdd = "odd";
foreach (self::get_links() as $action => $description) {
foreach (DevelopmentAdmin::get_links() as $action => $description) {
echo "<li class=\"$evenOdd\"><a href=\"{$base}dev/graphql/$action\"><b>/dev/graphql/$action:</b>"
. " $description</a></li>\n";
$evenOdd = ($evenOdd == "odd") ? "even" : "odd";
Expand All @@ -74,7 +74,7 @@ public function index(HTTPRequest $request)
} else {
echo "SILVERSTRIPE CMS GRAPHQL TOOLS\n--------------------------\n\n";
echo "You can execute any of the following commands:\n\n";
foreach (self::get_links() as $action => $description) {
foreach (DevelopmentAdmin::get_links() as $action => $description) {
echo " sake dev/graphql/$action: $description\n";
}
echo "\n\n";
Expand Down
2 changes: 1 addition & 1 deletion src/Middleware/QueryCachingMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function getCache(): CacheInterface
return $this->cache;
}

public function setCache(CacheInterface $cache): self
public function setCache(CacheInterface $cache): QueryCachingMiddleware
{
$this->cache = $cache;
return $this;
Expand Down
2 changes: 1 addition & 1 deletion src/PersistedQuery/FileProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getByID(string $queryID, string $schemaKey = 'default'): ?string
return isset($mapping[$queryID]) ? $mapping[$queryID] : null;
}

public function setSchemaMapping(array $mapping): self
public function setSchemaMapping(array $mapping): FileProvider
{
$this->schemaToPath = $mapping;

Expand Down
4 changes: 2 additions & 2 deletions src/PersistedQuery/HTTPProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function getByID(string $queryID, string $schemaKey = 'default'): ?string
return isset($mapping[$queryID]) ? $mapping[$queryID] : null;
}

public function setSchemaMapping(array $mapping): self
public function setSchemaMapping(array $mapping): HTTPProvider
{
foreach ($mapping as $schemaKey => $url) {
if (!filter_var($url, FILTER_VALIDATE_URL)) {
Expand All @@ -128,7 +128,7 @@ public function getSchemaMapping(): array
return $this->schemaToURL;
}

public function setClient(HTTPClient $client): self
public function setClient(HTTPClient $client): HTTPProvider
{
$this->client = $client;

Expand Down
2 changes: 1 addition & 1 deletion src/PersistedQuery/JSONStringProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public function getByID(string $queryID, string $schemaKey = 'default'): ?string
return isset($mapping[$queryID]) ? $mapping[$queryID] : null;
}

public function setSchemaMapping(array $mapping): self
public function setSchemaMapping(array $mapping): JSONStringProvider
{
foreach ($mapping as $schemaKey => $queryMap) {
if (!is_string($queryMap)) {
Expand Down
2 changes: 1 addition & 1 deletion src/PersistedQuery/PersistedQueryMappingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function getByID(string $queryID, string $schemaKey = 'default'): ?string
/**
* Sets mapping of query mapping to schema keys
*/
public function setSchemaMapping(array $mapping): self;
public function setSchemaMapping(array $mapping): PersistedQueryMappingProvider;

public function getSchemaMapping(): array;
}
10 changes: 5 additions & 5 deletions src/QueryHandler/QueryHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class QueryHandler implements
*/
private array $contextProviders = [];

private array $errorFormatter = [self::class, 'formatError'];
private array $errorFormatter = [QueryHandler::class, 'formatError'];

/**
* @config
Expand Down Expand Up @@ -226,7 +226,7 @@ public function serialiseResult(ExecutionResult $executionResult): array
* @param callable $errorFormatter
* @return QueryHandler
*/
public function setErrorFormatter(callable $errorFormatter): self
public function setErrorFormatter(callable $errorFormatter): QueryHandler
{
$this->errorFormatter = $errorFormatter;
return $this;
Expand All @@ -236,7 +236,7 @@ public function setErrorFormatter(callable $errorFormatter): self
* @param callable $errorHandler
* @return QueryHandler
*/
public function setErrorHandler(callable $errorHandler): self
public function setErrorHandler(callable $errorHandler): QueryHandler
{
$this->errorHandler = $errorHandler;
return $this;
Expand All @@ -254,7 +254,7 @@ public function getMiddlewares(): array
* @param QueryMiddleware[] $middlewares
* @return $this
*/
public function setMiddlewares(array $middlewares): self
public function setMiddlewares(array $middlewares): QueryHandler
{
foreach ($middlewares as $middleware) {
if ($middleware instanceof QueryMiddleware) {
Expand All @@ -268,7 +268,7 @@ public function setMiddlewares(array $middlewares): self
* @param QueryMiddleware $middleware
* @return $this
*/
public function addMiddleware(QueryMiddleware $middleware): self
public function addMiddleware(QueryMiddleware $middleware): QueryHandler
{
$this->middlewares[] = $middleware;
return $this;
Expand Down
4 changes: 2 additions & 2 deletions src/QueryHandler/QueryStateProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ public function __construct()

public static function get(array $context): Configuration
{
return $context[self::KEY] ?? new Configuration();
return $context[QueryStateProvider::KEY] ?? new Configuration();
}

public function provideContext(): array
{
return [
self::KEY => $this->queryState,
QueryStateProvider::KEY => $this->queryState,
];
}
}
4 changes: 2 additions & 2 deletions src/QueryHandler/RequestContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(HTTPRequest $request)
*/
public static function get(array $context)
{
return $context[self::HTTP_METHOD] ?? null;
return $context[RequestContextProvider::HTTP_METHOD] ?? null;
}

/**
Expand All @@ -46,7 +46,7 @@ public function provideContext(): array
}

return [
self::HTTP_METHOD => $method,
RequestContextProvider::HTTP_METHOD => $method,
];
}
}
4 changes: 2 additions & 2 deletions src/QueryHandler/SchemaConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(SchemaConfig $schemaConfig)
*/
public static function get(array $context): SchemaConfig
{
return $context[self::KEY] ?? new SchemaConfig();
return $context[SchemaConfigProvider::KEY] ?? new SchemaConfig();
}

/**
Expand All @@ -39,7 +39,7 @@ public static function get(array $context): SchemaConfig
public function provideContext(): array
{
return [
self::KEY => $this->schemaConfig,
SchemaConfigProvider::KEY => $this->schemaConfig,
];
}
}
4 changes: 2 additions & 2 deletions src/QueryHandler/TokenContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function __construct(string $token = '')
*/
public static function get(array $context): ?string
{
return $context[self::KEY] ?? null;
return $context[TokenContextProvider::KEY] ?? null;
}

/**
Expand All @@ -38,7 +38,7 @@ public static function get(array $context): ?string
public function provideContext(): array
{
return [
self::KEY => $this->token,
TokenContextProvider::KEY => $this->token,
];
}
}
4 changes: 2 additions & 2 deletions src/QueryHandler/UserContextProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function __construct(?Member $member = null)

public static function get(array $context): ?Member
{
return $context[self::KEY] ?? null;
return $context[UserContextProvider::KEY] ?? null;
}

/**
Expand All @@ -32,7 +32,7 @@ public static function get(array $context): ?Member
public function provideContext(): array
{
return [
self::KEY => $this->member,
UserContextProvider::KEY => $this->member,
];
}
}
6 changes: 3 additions & 3 deletions src/Schema/BulkLoader/AbstractBulkLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function __construct(array $include = [], array $exclude = [])
* @param array $include
* @return $this
*/
public function include(array $include): self
public function include(array $include): AbstractBulkLoader
{
$this->includeList = $include;

Expand All @@ -53,7 +53,7 @@ public function include(array $include): self
* @param array $exclude
* @return $this
*/
public function exclude(array $exclude): self
public function exclude(array $exclude): AbstractBulkLoader
{
$this->excludeList = $exclude;

Expand All @@ -65,7 +65,7 @@ public function exclude(array $exclude): self
* @return AbstractBulkLoader
* @throws SchemaBuilderException
*/
public function applyConfig(array $config): self
public function applyConfig(array $config): AbstractBulkLoader
{
Schema::assertValidConfig($config, ['include', 'exclude'], ['include']);
$include = $config['include'];
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/BulkLoader/BulkLoaderSet.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function __construct(array $loaders = [], ?Collection $initialCollection
* @return $this
* @throws SchemaBuilderException
*/
public function applyConfig(array $config): self
public function applyConfig(array $config): BulkLoaderSet
{
$registry = Registry::inst();
foreach ($config as $loaderID => $loaderConfig) {
Expand All @@ -67,7 +67,7 @@ public function applyConfig(array $config): self
* @param AbstractBulkLoader $loader
* @return $this
*/
public function addLoader(AbstractBulkLoader $loader): self
public function addLoader(AbstractBulkLoader $loader): BulkLoaderSet
{
$this->loaders[] = $loader;

Expand Down Expand Up @@ -101,7 +101,7 @@ public function process(): Collection
* @param array $loaders
* @return $this
*/
public function setLoaders(array $loaders): self
public function setLoaders(array $loaders): BulkLoaderSet
{
foreach ($loaders as $loader) {
if (!$loader instanceof AbstractBulkLoader) {
Expand Down
6 changes: 3 additions & 3 deletions src/Schema/BulkLoader/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function __construct(array $manifest = [])
* @return $this
* @throws Exception
*/
public function setManifest(array $manifest): self
public function setManifest(array $manifest): Collection
{
$this->manifest = $manifest;

Expand All @@ -42,7 +42,7 @@ public function setManifest(array $manifest): self
* @param string $class
* @return $this
*/
public function removeClass(string $class): self
public function removeClass(string $class): Collection
{
unset($this->manifest[$class]);

Expand All @@ -53,7 +53,7 @@ public function removeClass(string $class): self
* @param string $path
* @return $this
*/
public function removeFile(string $path): self
public function removeFile(string $path): Collection
{
$class = array_search($path, $this->manifest ?? []);
unset($this->manifest[$class]);
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/BulkLoader/ExtensionLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ExtensionLoader extends AbstractBulkLoader

public static function getIdentifier(): string
{
return self::IDENTIFIER;
return ExtensionLoader::IDENTIFIER;
}

public function collect(Collection $collection): Collection
Expand Down
2 changes: 1 addition & 1 deletion src/Schema/BulkLoader/FilepathLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FilepathLoader extends AbstractBulkLoader

public static function getIdentifier(): string
{
return self::IDENTIFIER;
return FilepathLoader::IDENTIFIER;
}

public function collect(Collection $collection): Collection
Expand Down
Loading

0 comments on commit 80bdc3b

Please sign in to comment.