Skip to content

Commit

Permalink
[Change] Apply code style using PHP Coding Standards Fixer (#733)
Browse files Browse the repository at this point in the history
  • Loading branch information
bumbummen99 authored Dec 2, 2024
1 parent bf0201d commit adbfd0f
Show file tree
Hide file tree
Showing 116 changed files with 189 additions and 483 deletions.
1 change: 0 additions & 1 deletion src/GameQ/Autoloader.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
* @codeCoverageIgnore
*/
spl_autoload_register(function ($class) {

// project-specific namespace prefix
$prefix = 'GameQ\\';

Expand Down
21 changes: 0 additions & 21 deletions src/GameQ/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/
class Buffer
{

/**
* Constants for the byte code types we need to read as
*/
Expand Down Expand Up @@ -79,7 +78,6 @@ class Buffer
*/
public function __construct($data, $number_type = self::NUMBER_TYPE_LITTLEENDIAN)
{

$this->number_type = $number_type;
$this->data = $data;
$this->length = strlen($data);
Expand All @@ -92,7 +90,6 @@ public function __construct($data, $number_type = self::NUMBER_TYPE_LITTLEENDIAN
*/
public function getData()
{

return $this->data;
}

Expand All @@ -103,7 +100,6 @@ public function getData()
*/
public function getBuffer()
{

return substr($this->data, $this->index);
}

Expand All @@ -114,7 +110,6 @@ public function getBuffer()
*/
public function getLength()
{

return max($this->length - $this->index, 0);
}

Expand All @@ -128,7 +123,6 @@ public function getLength()
*/
public function read($length = 1)
{

if (($length + $this->index) > $this->length) {
throw new Exception("Unable to read length={$length} from buffer. Bad protocol format or return?");
}
Expand All @@ -149,7 +143,6 @@ public function read($length = 1)
*/
public function readLast()
{

$len = strlen($this->data);
$string = $this->data[strlen($this->data) - 1];
$this->data = substr($this->data, 0, $len - 1);
Expand All @@ -167,7 +160,6 @@ public function readLast()
*/
public function lookAhead($length = 1)
{

return substr($this->data, $this->index, $length);
}

Expand All @@ -178,7 +170,6 @@ public function lookAhead($length = 1)
*/
public function skip($length = 1)
{

$this->index += $length;
}

Expand All @@ -190,7 +181,6 @@ public function skip($length = 1)
*/
public function jumpto($index)
{

$this->index = min($index, $this->length - 1);
}

Expand All @@ -201,7 +191,6 @@ public function jumpto($index)
*/
public function getPosition()
{

return $this->index;
}

Expand All @@ -217,7 +206,6 @@ public function getPosition()
*/
public function readString($delim = "\x00")
{

// Get position of delimiter
$len = strpos($this->data, $delim, min($this->index, $this->length));

Expand All @@ -244,7 +232,6 @@ public function readString($delim = "\x00")
*/
public function readPascalString($offset = 0, $read_offset = false)
{

// Get the proper offset
$len = $this->readInt8();
$offset = max($len - $offset, 0);
Expand Down Expand Up @@ -272,7 +259,6 @@ public function readPascalString($offset = 0, $read_offset = false)
*/
public function readStringMulti($delims, &$delimfound = null)
{

// Get position of delimiters
$pos = [];
foreach ($delims as $delim) {
Expand Down Expand Up @@ -302,7 +288,6 @@ public function readStringMulti($delims, &$delimfound = null)
*/
public function readInt8()
{

$int = unpack('Cint', $this->read(1));

return $int['int'];
Expand All @@ -316,7 +301,6 @@ public function readInt8()
*/
public function readInt8Signed()
{

$int = unpack('cint', $this->read(1));

return $int['int'];
Expand All @@ -330,7 +314,6 @@ public function readInt8Signed()
*/
public function readInt16()
{

// Change the integer type we are looking up
switch ($this->number_type) {
case self::NUMBER_TYPE_BIGENDIAN:
Expand Down Expand Up @@ -358,7 +341,6 @@ public function readInt16()
*/
public function readInt16Signed()
{

// Read the data into a string
$string = $this->read(2);

Expand Down Expand Up @@ -416,7 +398,6 @@ public function readInt32($length = 4)
*/
public function readInt32Signed()
{

// Read the data into a string
$string = $this->read(4);

Expand All @@ -440,7 +421,6 @@ public function readInt32Signed()
*/
public function readInt64()
{

// We have the pack 64-bit codes available. See: http://php.net/manual/en/function.pack.php
if (version_compare(PHP_VERSION, '5.6.3') >= 0 && PHP_INT_SIZE == 8) {
// Change the integer type we are looking up
Expand Down Expand Up @@ -488,7 +468,6 @@ public function readInt64()
*/
public function readFloat32()
{

// Read the data into a string
$string = $this->read(4);

Expand Down
1 change: 0 additions & 1 deletion src/GameQ/Filters/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ abstract class Base
*/
public function __construct(array $options = [])
{

$this->options = $options;
}

Expand Down
42 changes: 21 additions & 21 deletions src/GameQ/Filters/Normalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,24 @@ class Normalize extends Base
*/
public function apply(array $result, Server $server)
{
/* Determine if there is data to be processed */
// Determine if there is data to be processed
if (! empty($result)) {
/* Handle unit test data generation */
// Handle unit test data generation
if ($this->writeTestData) {
/* Initialize potential data for unit testing **/
// Initialize potential data for unit testing
$unitTestData = [ ];

/* Add the initial result to the unit test data */
// Add the initial result to the unit test data
$unitTestData['raw'][$server->id()] = $result;
}

/* Grab the normalize definition from the server's protocol */#
/* Grab the normalize definition from the server's protocol *///
$this->normalize = $server->protocol()->getNormalize();

/* Normalize general information */
// Normalize general information
$result = array_merge($result, $this->check('general', $result));

/* Normalize player information */
// Normalize player information
if (isset($result['players']) && count($result['players']) > 0) {
foreach ($result['players'] as $key => $player) {
$result['players'][$key] = array_merge($player, $this->check('player', $player));
Expand All @@ -82,7 +82,7 @@ public function apply(array $result, Server $server)
$result['players'] = [];
}

/* Normalize team information */
// Normalize team information
if (isset($result['teams']) && count($result['teams']) > 0) {
foreach ($result['teams'] as $key => $team) {
$result['teams'][$key] = array_merge($team, $this->check('team', $team));
Expand All @@ -91,20 +91,20 @@ public function apply(array $result, Server $server)
$result['teams'] = [];
}

/* Handle unit test data generation */
// Handle unit test data generation
if ($this->writeTestData) {
/* Add the filtered result to the unit test data */
// Add the filtered result to the unit test data
$unitTestData['filtered'][$server->id()] = $result;

/* Persist the collected data to the tests directory */
// Persist the collected data to the tests directory
file_put_contents(
sprintf('%s/../../../tests/Filters/Providers/Normalize/%s_1.json', __DIR__, $server->protocol()->getProtocol()),
json_encode($unitTestData, JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR)
);
}
}

/* Return the filtered result */
// Return the filtered result
return $result;
}

Expand All @@ -118,35 +118,35 @@ public function apply(array $result, Server $server)
*/
protected function check($section, array $data)
{
/* Initialize the normalized output */
// Initialize the normalized output
$normalized = [];

/* Ensure the provided section is defined */
// Ensure the provided section is defined
if (isset($this->normalize[$section])) {
/* Process each mapping individually */
// Process each mapping individually
foreach ($this->normalize[$section] as $target => $source) {
/* Treat explicit source like implicit sources */
// Treat explicit source like implicit sources
if (! is_array($source)) {
$source = [$source];
}

/* Find the first possible source */
// Find the first possible source
foreach ($source as $s) {
/* Determine if the current source does exist */
// Determine if the current source does exist
if (array_key_exists($s, $data)) {
/* Add the normalized mapping */
// Add the normalized mapping
$normalized['gq_'.$target] = $data[$s];
break;
}
}

/* Write null in case no source was found */
// Write null in case no source was found
// TODO: Remove this in the next major version.
$normalized['gq_'.$target] = isset($normalized['gq_'.$target]) ? $normalized['gq_'.$target] : null;
}
}

/* Return the normalized data */
// Return the normalized data
return $normalized;
}
}
13 changes: 6 additions & 7 deletions src/GameQ/Filters/Secondstohuman.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
*/
class Secondstohuman extends Base
{

/**
* The options key for setting the data key(s) to look for to convert
*/
Expand Down Expand Up @@ -85,21 +84,21 @@ public function apply(array $result, Server $server)
{
return Arr::recursively($result, function ($value, $key, RecursiveArrayIterator $iterator) {
if (
/* Only process whitelisted keys */
// Only process whitelisted keys
(in_array($key, $this->options[self::OPTION_TIMEKEYS])) &&
/* Only process numeric values (float, integer, string) */
// Only process numeric values (float, integer, string)
(is_numeric($value))
) {
/* Ensure the value is float */
// Ensure the value is float
if (! is_float($value)) {
$value = floatval($value);
}

/* Add a new element to the result */
// Add a new element to the result
$iterator->offsetSet(
/* Modify the current key */
// Modify the current key
sprintf(self::RESULT_KEY, $key),
/* Format the provided time */
// Format the provided time
sprintf(
'%02d:%02d:%02d',
(int)floor($value / 3600), // Hours
Expand Down
Loading

0 comments on commit adbfd0f

Please sign in to comment.