Skip to content

Commit

Permalink
Run project through psr-12
Browse files Browse the repository at this point in the history
  • Loading branch information
nmeri17 committed Apr 25, 2023
1 parent 56120ae commit 904abbb
Show file tree
Hide file tree
Showing 723 changed files with 26,482 additions and 23,934 deletions.
49 changes: 1 addition & 48 deletions .php_cs.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,54 +6,7 @@
$config = new PhpCsFixer\Config();
$config
->setRules([
"array_syntax" => ["syntax" => "short"],
"binary_operator_spaces" => [
"operators" => [
"=" => "align_single_space_minimal",
"=>" => "align_single_space_minimal",
],
],
"concat_space" => ["spacing" => "none"],
"ordered_imports" => ["sort_algorithm" => "alpha"],
"no_extra_blank_lines" => true,
"no_whitespace_in_blank_line" => true,
"phpdoc_align" => [
"align" => "left",
],
"phpdoc_no_access" => true,
"phpdoc_no_package" => true,
"phpdoc_scalar" => true,
"phpdoc_single_line_var_spacing" => true,
"phpdoc_summary" => true,
"phpdoc_to_comment" => true,
"phpdoc_trim" => true,
"phpdoc_types" => true,
"phpdoc_var_without_name" => true,
"return_type_declaration" => true,
"single_quote" => false,
//"sort_array_syntax" => ["syntax" => "alphabetical"],
"standardize_not_equals" => true,
"ternary_operator_spaces" => true,
"trailing_comma_in_multiline" => true,
"trim_array_spaces" => true,
"no_unused_imports" => true,
// "declare_strict_types" => true,
// "single_line_comment_style" => ["comment_types" => ["hash"]],
"blank_line_before_statement" => true, // <--- New rule
"line_ending" => true, // <--- New rule
"linebreak_after_opening_tag" => true,
"no_leading_namespace_whitespace" => true,
"single_blank_line_before_namespace" => false,
"no_trailing_comma_in_singleline_array" => true,
"no_whitespace_before_comma_in_array" => true,
"lowercase_keywords" => true,
"php_unit_test_class_requires_covers" => false,
// "php_unit_strict" => true,
// "php_unit_test_case_static_method_calls" => ["call_type" => "this"],
"braces" => ["allow_single_line_closure" => true, "position_after_functions_and_oop_constructs" => "same"], // <--- Updated rule
//"line_length" => ["max" => 75], // <--- New rule
"single_quote" => false, // <--- New rule
"group_import" => true, // <--- New rule
"@PSR12" => true
])
->setFinder($finder);

Expand Down
27 changes: 13 additions & 14 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
<?php

/**
* Using this for testing the traditional setup without creating modules and other protocols on the starter project
*/
use Suphle\Server\ModuleWorkerAccessor;
/**
* Using this for testing the traditional setup without creating modules and other protocols on the starter project
*/
use Suphle\Server\ModuleWorkerAccessor;

use Suphle\Tests\Mocks\PublishedTestModules;
use Suphle\Tests\Mocks\PublishedTestModules;

require_once "vendor/autoload.php";
require_once "vendor/autoload.php";

$writeHeaders = php_sapi_name() !== "cli";
$writeHeaders = php_sapi_name() !== "cli";

echo (new ModuleWorkerAccessor(new PublishedTestModules, true))
echo (new ModuleWorkerAccessor(new PublishedTestModules(), true))

->buildIdentifier()->getRequestRenderer(

$_GET["suphle_path"], $writeHeaders
)
->render();
?>
->buildIdentifier()->getRequestRenderer(
$_GET["suphle_path"],
$writeHeaders
)
->render();
26 changes: 13 additions & 13 deletions manual-flow-starter.php
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
<?php
use Suphle\Server\ModuleWorkerAccessor;

use Suphle\Tests\Mocks\PublishedTestModules;
use Suphle\Server\ModuleWorkerAccessor;

require_once "vendor/autoload.php";
use Suphle\Tests\Mocks\PublishedTestModules;

/**
* This is for use when handling traditional requests i.e. without RR
*/
$handlerIdentifier = new PublishedTestModules;
require_once "vendor/autoload.php";

echo("Booting Modules...\n");
/**
* This is for use when handling traditional requests i.e. without RR
*/
$handlerIdentifier = new PublishedTestModules();

$accessor = (new ModuleWorkerAccessor($handlerIdentifier, false))
echo("Booting Modules...\n");

->buildIdentifier();
$accessor = (new ModuleWorkerAccessor($handlerIdentifier, false))

echo("Listening for requests...\n");
->buildIdentifier();

$accessor->getQueueWorker()->processTasks();
?>
echo("Listening for requests...\n");

$accessor->getQueueWorker()->processTasks();
8 changes: 4 additions & 4 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Rector\Set\ValueObject\LevelSetList;

return static function (RectorConfig $rectorConfig): void {

$rectorConfig->paths([
__DIR__ . '/src',

Expand All @@ -24,7 +24,7 @@
$rectorConfig->rule(SplitGroupedConstantsAndPropertiesRector::class);

// define sets of rules
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82
]);
$rectorConfig->sets([
LevelSetList::UP_TO_PHP_82
]);
};
73 changes: 42 additions & 31 deletions src/Adapters/Cache/InMemoryCache.php
Original file line number Diff line number Diff line change
@@ -1,55 +1,66 @@
<?php
namespace Suphle\Adapters\Cache;

use Suphle\Contracts\IO\CacheManager;
namespace Suphle\Adapters\Cache;

use Exception;
use Suphle\Contracts\IO\CacheManager;

class InMemoryCache implements CacheManager {
use Exception;

protected array $store = [], $tags = [];
class InMemoryCache implements CacheManager
{
protected array $store = [];
protected array $tags = [];

public function setupClient ():void {
public function setupClient(): void
{

// error 404: no client to setup
}
// error 404: no client to setup
}

public function getItem (string $key, callable $storeOnAbsence = null) {
public function getItem(string $key, callable $storeOnAbsence = null)
{

if (array_key_exists($key, $this->store))
if (array_key_exists($key, $this->store)) {

return $this->store[$key];
return $this->store[$key];
}

if (is_null($storeOnAbsence)) return;
if (is_null($storeOnAbsence)) {
return;
}

$toStore = $storeOnAbsence();
$toStore = $storeOnAbsence();

if (is_null($toStore))
if (is_null($toStore)) {

throw new Exception("Cache data source cannot return null");
throw new Exception("Cache data source cannot return null");
}

$this->saveItem($key, $toStore);
$this->saveItem($key, $toStore);

return $toStore;
}
return $toStore;
}

public function saveItem (string $key, $data):void {
public function saveItem(string $key, $data): void
{

$this->store[$key] = $data;
}
$this->store[$key] = $data;
}

public function tagItem (string $key, $data):void {
public function tagItem(string $key, $data): void
{

if (!array_key_exists($key, $this->tags))
if (!array_key_exists($key, $this->tags)) {

$this->tags[$key] = [];
$this->tags[$key] = [];
}

$this->tags[$key][] = $data;
}
$this->tags[$key][] = $data;
}

public function deleteItem (string $key) {
public function deleteItem(string $key)
{

unset($this->store[$key]);
}
}
?>
unset($this->store[$key]);
}
}
95 changes: 52 additions & 43 deletions src/Adapters/Cache/PredisAdapter.php
Original file line number Diff line number Diff line change
@@ -1,75 +1,84 @@
<?php
namespace Suphle\Adapters\Cache;

use Suphle\Contracts\{IO\CacheManager, Config\CacheClient as CacheConfig};
namespace Suphle\Adapters\Cache;

use Predis\Client;
use Suphle\Contracts\{IO\CacheManager, Config\CacheClient as CacheConfig};

use Exception;
use Predis\Client;

class PredisAdapter implements CacheManager {
use Exception;

final const TAG_KEY = "_reserved_key_tags";
class PredisAdapter implements CacheManager
{
final public const TAG_KEY = "_reserved_key_tags";

protected Client $client;
protected Client $client;

public function __construct (
public function __construct(
protected readonly CacheConfig $cacheConfig
) {

protected readonly CacheConfig $cacheConfig
) {
//
}

//
}
public function setupClient(): void
{

public function setupClient ():void {
$this->client = new Client($this->cacheConfig->getCredentials());
}

$this->client = new Client($this->cacheConfig->getCredentials());
}
public function getItem(string $key, callable $storeOnAbsence = null)
{

public function getItem (string $key, callable $storeOnAbsence = null) {
$foundData = $this->client->get($key);

$foundData = $this->client->get($key);
if (!is_null($foundData) || is_null($storeOnAbsence)) {

if (!is_null($foundData) || is_null($storeOnAbsence))
return $foundData;
}

return $foundData;
$toStore = $storeOnAbsence();

$toStore = $storeOnAbsence();
if (is_null($toStore)) {

if (is_null($toStore))
throw new Exception("Cache data source cannot return null");
}

throw new Exception("Cache data source cannot return null");
$this->saveItem($key, $toStore);

$this->saveItem($key, $toStore);
return $toStore;
}

return $toStore;
}
public function saveItem(string $key, $data): void
{

public function saveItem (string $key, $data):void {
$this->client->set($key, $data);
}

$this->client->set($key, $data);
}
public function tagItem(string $key, $data): void
{

public function tagItem (string $key, $data):void {
$dataNode = $this->client;

$dataNode = $this->client;
$allTags = $dataNode->get(self::TAG_KEY);

$allTags = $dataNode->get(self::TAG_KEY);
if (is_null($allTags)) {
$allTags = [];
}

if (is_null($allTags)) $allTags = [];
if (!array_key_exists($key, $allTags)) {

if (!array_key_exists($key, $allTags))
$allTags[$key] = [];
}

$allTags[$key] = [];
$allTags[$key][] = $data;

$allTags[$key][] = $data;
$dataNode->set(self::TAG_KEY, $allTags);
}

$dataNode->set(self::TAG_KEY, $allTags);
}
public function deleteItem(string $key)
{

public function deleteItem (string $key) {

$this->client->set($key, null);
}
}
?>
$this->client->set($key, null);
}
}
Loading

0 comments on commit 904abbb

Please sign in to comment.