Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solve warnings and remove deprecated code #729

Merged
merged 33 commits into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
ff76c50
[Fix] PHPDoc annotations for improved static analysis,
bumbummen99 Nov 28, 2024
170f17c
[Fix] Deprecated pass preg_replace subject as null,
bumbummen99 Nov 28, 2024
6fa9e1b
[Fix] Implicit conversion losing precision from float to integer
bumbummen99 Nov 28, 2024
c98c6d8
[Fix] Deprecated dynamic property in test Issue588
bumbummen99 Nov 28, 2024
c2804d1
[Add] Array helper Concern and function to use RecursiveArrayIterator…
bumbummen99 Nov 28, 2024
eedc9b8
Codestyle
bumbummen99 Nov 28, 2024
e5d15bb
Codestyle and remove debug code
bumbummen99 Nov 28, 2024
269d6f3
Codestyle
bumbummen99 Nov 28, 2024
8ecac16
[Fix] Remove non backwards compatible code
bumbummen99 Nov 28, 2024
3d9c681
[Fix] Typo
bumbummen99 Nov 28, 2024
b2d1eb4
[Fix] Remove return type hint
bumbummen99 Nov 28, 2024
4a916f8
[Fix] Remove null coalesce operator
bumbummen99 Nov 28, 2024
25b80c5
[Fix] check array key before evaluating boolean value
bumbummen99 Nov 28, 2024
1cab139
[Change] Remove unused variable
bumbummen99 Nov 28, 2024
e586045
[Fix] Remove function parameter type hint
bumbummen99 Nov 28, 2024
69443a5
[Fix] Remove further scalar type hints
bumbummen99 Nov 28, 2024
39be9d7
[Change] Add comments to know what is to be deprecated,
bumbummen99 Nov 28, 2024
fa0dbc2
Codestyle
bumbummen99 Nov 28, 2024
94a0d50
[Change] Use dedicated helper classes over Traits to prevent pollutin…
bumbummen99 Nov 29, 2024
f3ff970
Codestyle
bumbummen99 Nov 29, 2024
6c9afac
Codestyle
bumbummen99 Nov 29, 2024
f522c41
[Fix] keep build logs directory
bumbummen99 Nov 29, 2024
626ee73
[Fix] Handle different way to access array reference,
bumbummen99 Nov 29, 2024
e773391
Fix missing static
bumbummen99 Nov 29, 2024
1a9b045
[Change] Protocol packetResponse parameter default value to empty arr…
bumbummen99 Nov 29, 2024
10f6071
[Fix] PHPDoc throws for all Protocols
bumbummen99 Nov 29, 2024
39c4e54
[Fix] Source protocol skip non´challenge response
bumbummen99 Nov 29, 2024
cecf107
Codestyle
bumbummen99 Nov 29, 2024
8145995
Codestyle
bumbummen99 Nov 29, 2024
e6523ed
[Change] Install act for all users in DevContainer
bumbummen99 Nov 29, 2024
9d82376
[Change] Use Coveralis action and enable parallel support
bumbummen99 Nov 29, 2024
4f81d51
[Remove] Duplicate step in workflow
bumbummen99 Nov 29, 2024
4f34167
[Change] Add clover path to Coveralis action
bumbummen99 Nov 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"build": {
"dockerfile": "docker/Dockerfile"
},
"features": {
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
},
"postCreateCommand": ".devcontainer/postCreate.sh",
"remoteUser": "vscode"
}
11 changes: 8 additions & 3 deletions .devcontainer/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
# Define the DevContainer template to be used as the base
ARG TAG=8.2-bullseye
FROM mcr.microsoft.com/vscode/devcontainers/php:$TAG
ARG PHP=8.3
ARG DISTRO=bullseye

FROM mcr.microsoft.com/vscode/devcontainers/php:$PHP-$DISTRO

# Update the registry once
RUN apt-get update

# Install ext-bz2
RUN apt-get install -y libbz2-dev \
&& docker-php-ext-configure bz2 \
&& docker-php-ext-install bz2
&& docker-php-ext-install bz2

# Install act
RUN curl --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/nektos/act/master/install.sh | sudo bash -s -- -b /usr/local/bin
28 changes: 15 additions & 13 deletions .github/workflows/Tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,10 @@ jobs:
strategy:
fail-fast: false
matrix:
php: [7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1]
php: [5.6, 7.0, 7.1, 7.2, 7.3, 7.4, 8.0, 8.1, 8.2, 8.3]
experimental: [false]
composer-extra: ['']
include:
- php: 5.6
experimental: false
- php: 8.2
experimental: false
- php: 8.3
experimental: false
- php: 8.4
experimental: true
composer-extra: '--ignore-platform-req=php+'
Expand Down Expand Up @@ -66,15 +60,23 @@ jobs:
run: vendor/bin/phpunit -c phpunit.xml --verbose

- name: Upload Coveralls coverage
if: github.repository == 'Austinb/GameQ'
env:
COVERALLS_REPO_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
composer global require php-coveralls/php-coveralls
php ~/.composer/vendor/bin/php-coveralls --coverage_clover=build/logs/clover.xml -v
uses: coverallsapp/github-action@v2
with:
parallel: true
file: build/logs/clover.xml

- name: Upload Scrutinizer coverage
uses: sudo-bot/action-scrutinizer@latest
if: github.repository == 'Austinb/GameQ'
with:
cli-args: "--format=php-clover build/logs/clover.xml --revision=${{ github.event.pull_request.head.sha || github.sha }}"

Finish:
needs: CI
if: ${{ always() }}
runs-on: ubuntu-latest
steps:
- name: Coveralls Finished
uses: coverallsapp/github-action@v2
with:
parallel-finished: true
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ composer.phar
# PHPUnit
.phpunit.result.cache
coverage/
build/logs/
build/logs/*
!build/logs/.gitkeep
Empty file added build/logs/.gitkeep
Empty file.
8 changes: 4 additions & 4 deletions src/GameQ/Buffer.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,28 +46,28 @@ class Buffer
/**
* The number type we use for reading integers. Defaults to little endian
*
* @type string
* @var string
*/
private $number_type = self::NUMBER_TYPE_LITTLEENDIAN;

/**
* The original data
*
* @type string
* @var string
*/
private $data;

/**
* The original data
*
* @type int
* @var int
*/
private $length;

/**
* Position of pointer
*
* @type int
* @var int
*/
private $index = 0;

Expand Down
4 changes: 2 additions & 2 deletions src/GameQ/Filters/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

namespace GameQ\Filters;

use GameQ\Concerns\WithArrayHelpers;
use GameQ\Server;

/**
Expand All @@ -27,11 +28,10 @@
*/
abstract class Base
{

/**
* Holds the options for this instance of the filter
*
* @type array
* @var array
*/
protected $options = [];

Expand Down
133 changes: 76 additions & 57 deletions src/GameQ/Filters/Normalize.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,111 +23,130 @@
/**
* Class Normalize
*
* This Filter is responsible for normalizing the provided result's
* property names to the GameQ standard.
*
* @package GameQ\Filters
*/
class Normalize extends Base
{
/**
* Determines if data should be persisted for unit testing.
*
* @var bool
*/
protected $writeTestData = false;

/**
* Holds the protocol specific normalize information
*
* @type array
* @var array
*/
protected $normalize = [];

/**
* Apply this filter
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*
* @param array $result
* @param \GameQ\Server $server
*
* @return array
*/
public function apply(array $result, Server $server)
{
/* Determine if there is data to be processed */
if (! empty($result)) {
/* Handle unit test data generation */
if ($this->writeTestData) {
/* Initialize potential data for unit testing **/
$unitTestData = [ ];

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

// No result passed so just return
if (empty($result)) {
return $result;
}

//$data = [ ];
//$data['raw'][$server->id()] = $result;
/* Grab the normalize definition from the server's protocol */#
$this->normalize = $server->protocol()->getNormalize();

// Grab the normalize for this protocol for the specific server
$this->normalize = $server->protocol()->getNormalize();
/* Normalize general information */
$result = array_merge($result, $this->check('general', $result));

// Do general information
$result = array_merge($result, $this->check('general', $result));
/* 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));
}
} else {
$result['players'] = [];
}

// Do player information
if (isset($result['players']) && count($result['players']) > 0) {
// Iterate
foreach ($result['players'] as $key => $player) {
$result['players'][$key] = array_merge($player, $this->check('player', $player));
/* 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));
}
} else {
$result['teams'] = [];
}
} else {
$result['players'] = [];
}

// Do team information
if (isset($result['teams']) && count($result['teams']) > 0) {
// Iterate
foreach ($result['teams'] as $key => $team) {
$result['teams'][$key] = array_merge($team, $this->check('team', $team));
/* Handle unit test data generation */
if ($this->writeTestData) {
/* Add the filtered result to the unit test data */
$unitTestData['filtered'][$server->id()] = $result;

/* 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)
);
}
} else {
$result['teams'] = [];
}

//$data['filtered'][$server->id()] = $result;
/*file_put_contents(
sprintf('%s/../../../tests/Filters/Providers/Normalize/%s_1.json', __DIR__, $server->protocol()->getProtocol()),
json_encode($data, JSON_UNESCAPED_UNICODE | JSON_PARTIAL_OUTPUT_ON_ERROR)
);*/

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

/**
* Check a section for normalization
*
* @param $section
* @param $data
* @param string $section
* @param array $data
*
* @return array
*/
protected function check($section, $data)
protected function check($section, array $data)
{

// Normalized return array
/* Initialize the normalized output */
$normalized = [];

if (isset($this->normalize[$section]) && !empty($this->normalize[$section])) {
foreach ($this->normalize[$section] as $property => $raw) {
// Default the value for the new key as null
$value = null;

if (is_array($raw)) {
// Iterate over the raw property we want to use
foreach ($raw as $check) {
if (array_key_exists($check, $data)) {
$value = $data[$check];
break;
}
}
} else {
// String
if (array_key_exists($raw, $data)) {
$value = $data[$raw];
/* Ensure the provided section is defined */
if (isset($this->normalize[$section])) {
/* Process each mapping individually */
foreach ($this->normalize[$section] as $target => $source) {
/* Treat explicit source like implicit sources */
if (! is_array($source)) {
$source = [$source];
}

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

$normalized['gq_' . $property] = $value;
/* 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 $normalized;
}
}
Loading