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

Implement code quality checks #60

Merged
merged 36 commits into from
Apr 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
b51815d
Code style refactor
lanedirt Apr 9, 2024
ee5590b
Update BuildingQueueService.php
lanedirt Apr 9, 2024
0ea7a44
Update BuildingQueueService.php
lanedirt Apr 9, 2024
e94e196
Update phpstan.neon
lanedirt Apr 9, 2024
f6d4ef4
Code style refactor
lanedirt Apr 10, 2024
66953fe
Code style refactor
lanedirt Apr 10, 2024
2938da9
Update ResearchQueueService.php
lanedirt Apr 10, 2024
b52c13a
Code style refactor
lanedirt Apr 11, 2024
d3df85b
Add statically typed object structure
lanedirt Apr 11, 2024
155fb2f
Major refactor object definitions
lanedirt Apr 11, 2024
84540e4
Make resource page work with new structure
lanedirt Apr 12, 2024
0a059a9
Fix overview page
lanedirt Apr 12, 2024
abdf005
Fix resources and facilities
lanedirt Apr 12, 2024
4035384
Fix research page
lanedirt Apr 12, 2024
b1bf8ad
Update PlayerService.php
lanedirt Apr 12, 2024
c27f81f
Fix shipyard page
lanedirt Apr 12, 2024
0347d59
Fix fleet page
lanedirt Apr 12, 2024
4d92fca
Fix defense page
lanedirt Apr 12, 2024
4bcb56e
Fix ajax and techtree popups
lanedirt Apr 12, 2024
80e3aa4
Remove deprecated methods
lanedirt Apr 12, 2024
53d2fb9
Cleanup ObjectService
lanedirt Apr 12, 2024
811e937
Refactoring
lanedirt Apr 12, 2024
6317e10
Fix tests
lanedirt Apr 12, 2024
4178bb1
Fix all existing tests
lanedirt Apr 12, 2024
0774847
Code style refactor
lanedirt Apr 12, 2024
568e8ba
Refactor build queue system
lanedirt Apr 13, 2024
d54e0d9
Update templates
lanedirt Apr 13, 2024
f40e0c5
Restructure ViewModel queue
lanedirt Apr 13, 2024
8c6b61d
Move abstracts
lanedirt Apr 13, 2024
a80050b
Code style refactor
lanedirt Apr 13, 2024
8d148fb
Update object.blade.php
lanedirt Apr 13, 2024
029a5f3
Refactoring to simplify structure
lanedirt Apr 13, 2024
5abea8a
Change planet resource to float
lanedirt Apr 13, 2024
f182517
Refactor tests, fix all phpstan warnings
lanedirt Apr 13, 2024
40dc429
Create run-phpstan-code-analysis.yml
lanedirt Apr 13, 2024
73d9c4e
Update run-phpstan-code-analysis.yml
lanedirt Apr 13, 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
30 changes: 30 additions & 0 deletions .github/workflows/run-phpstan-code-analysis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: PHPStan Code Analysis

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
phpstan-code-analysis:
runs-on: ubuntu-latest
steps:
- uses: shivammathur/setup-php@15c43e89cdef867065b0213be354c2841860869e
with:
php-version: '8.2'
- uses: actions/checkout@v3
- name: Copy .env
run: php -r "file_exists('.env') || copy('.env.example', '.env');"
- name: Composer update
run: composer update --lock
- name: Install Dependencies
run: composer install -q --no-ansi --no-interaction --no-scripts --no-progress --prefer-dist
- name: Generate key
run: php artisan key:generate
- name: Directory Permissions
run: chmod -R 777 storage bootstrap/cache
- name: PHPStan
uses: php-actions/phpstan@v3
with:
memory_limit: 256M
192 changes: 192 additions & 0 deletions app/GameObjects/BuildingObjects.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<?php

namespace OGame\GameObjects;

use OGame\GameObjects\Models\BuildingObject;
use OGame\GameObjects\Models\Fields\GameObjectAssets;
use OGame\GameObjects\Models\Fields\GameObjectPrice;
use OGame\GameObjects\Models\Fields\GameObjectProduction;
use OGame\GameObjects\Models\Fields\GameObjectRequirement;
use OGame\GameObjects\Models\Fields\GameObjectStorage;

class BuildingObjects
{
/**
* Returns all building objects.
*
* @return array<BuildingObject>
*/
public static function get() : array
{
$buildingObjectsNew = [];

// --- Metal Mine ---
$metalMine = new BuildingObject();
$metalMine->id = 1;
$metalMine->title = 'Metal Mine';
$metalMine->machine_name = 'metal_mine';
$metalMine->description = 'Used in the extraction of metal ore, metal mines are of primary importance to all emerging and established empires.';
$metalMine->description_long = 'Metal is the primary resource used in the foundation of your Empire. At greater depths, the mines can produce more output of viable metal for use in the construction of buildings, ships, defense systems, and research. As the mines drill deeper, more energy is required for maximum production. As metal is the most abundant of all resources available, its value is considered to be the lowest of all resources for trading.';

$metalMine->price = new GameObjectPrice(60, 15, 0, 0, 1.5);

$metalMine->production = new GameObjectProduction();
$metalMine->production->metal = 'return (30 * $building_level * pow((1.1), $building_level)) * (0.1 * $building_percentage);';
$metalMine->production->energy = 'return - (10 * $building_level * pow((1.1), $building_level)) * (0.1 * $building_percentage);';

$metalMine->assets = new GameObjectAssets();
$metalMine->assets->imgMicro = 'metal_mine_micro.jpg';
$metalMine->assets->imgSmall = 'metal_mine_small.jpg';
$buildingObjectsNew[] = $metalMine;
// --------------------

// --- Crystal Mine ---
$crystalMine = new BuildingObject();
$crystalMine->id = 2;
$crystalMine->title = 'Crystal Mine';
$crystalMine->machine_name = 'crystal_mine';
$crystalMine->description = 'Crystals are the main resource used to build electronic circuits and form certain alloy compounds.';
$crystalMine->description_long = 'Crystal mines supply the main resource used to produce electronic circuits and from certain alloy compounds. Mining crystal consumes some one and half times more energy than a mining metal, making crystal more valuable. Almost all ships and all buildings require crystal. Most crystals required to build spaceships, however, are very rare, and like metal can only be found at a certain depth. Therefore, building mines in deeper strata will increase the amount of crystal produced.';

$crystalMine->price = new GameObjectPrice(48, 24, 0, 0, 1.6);

$crystalMine->production = new GameObjectProduction();
$crystalMine->production->crystal = 'return (20 * $building_level * pow((1.1), $building_level)) * (0.1 * $building_percentage);';
$crystalMine->production->energy = 'return - (10 * $building_level * pow((1.1), $building_level)) * (0.1 * $building_percentage);';

$crystalMine->assets = new GameObjectAssets();
$crystalMine->assets->imgMicro = 'crystal_mine_micro.jpg';
$crystalMine->assets->imgSmall = 'crystal_mine_small.jpg';
$buildingObjectsNew[] = $crystalMine;
// --------------------

// --- Deuterium Synthesizer ---
$deuteriumSynthesizer = new BuildingObject();
$deuteriumSynthesizer->id = 3;
$deuteriumSynthesizer->title = 'Deuterium Synthesizer';
$deuteriumSynthesizer->machine_name = 'deuterium_synthesizer';
$deuteriumSynthesizer->description = 'Deuterium Synthesizers draw the trace Deuterium content from the water on a planet.';
$deuteriumSynthesizer->description_long = 'Deuterium is also called heavy hydrogen. It is a stable isotope of hydrogen with a natural abundance in the oceans of colonies of approximately one atom in 6500 of hydrogen (~154 PPM). Deuterium thus accounts for approximately 0.015% (on a weight basis, 0.030%) of all. Deuterium is processed by special synthesizers which can separate the water from the Deuterium using specially designed centrifuges. The upgrade of the synthesizer allows for increasing the amount of Deuterium deposits processed. Deuterium is used when carrying out sensor phalanx scans, viewing galaxies, as fuel for ships, and performing specialized research upgrades.';

$deuteriumSynthesizer->price = new GameObjectPrice(225, 75, 0, 0, 1.5);

$deuteriumSynthesizer->production = new GameObjectProduction();
$deuteriumSynthesizer->production->deuterium = 'return ((10 * $building_level * pow((1.1), $building_level)) * (-0.002 * $planet_temperature + 1.28)) * (0.1 * $building_percentage);';
$deuteriumSynthesizer->production->energy = 'return - (20 * $building_level * pow((1.1), $building_level)) * (0.1 * $building_percentage);';

$deuteriumSynthesizer->assets = new GameObjectAssets();
$deuteriumSynthesizer->assets->imgMicro = 'deuterium_synthesizer_micro.jpg';
$deuteriumSynthesizer->assets->imgSmall = 'deuterium_synthesizer_small.jpg';
$buildingObjectsNew[] = $deuteriumSynthesizer;
// --------------------

// --- Solar Plant ---
$solarPlant = new BuildingObject();
$solarPlant->id = 4;
$solarPlant->title = 'Solar Plant';
$solarPlant->machine_name = 'solar_plant';
$solarPlant->description = 'Solar power plants absorb energy from solar radiation. All mines need energy to operate.';
$solarPlant->description_long = 'Gigantic solar arrays are used to generate power for the mines and the deuterium synthesizer. As the solar plant is upgraded, the surface area of the photovoltaic cells covering the planet increases, resulting in a higher energy output across the power grids of your planet.';

$solarPlant->price = new GameObjectPrice(75, 30, 0, 0, 1.5);

$solarPlant->production = new GameObjectProduction();
$solarPlant->production->energy = 'return (20 * $building_level * pow((1.1), $building_level)) * (0.1 * $building_percentage);';

$solarPlant->assets = new GameObjectAssets();
$solarPlant->assets->imgMicro = 'solar_plant_micro.jpg';
$solarPlant->assets->imgSmall = 'solar_plant_small.jpg';
$buildingObjectsNew[] = $solarPlant;
// --------------------

// --- Fusion Reactor ---
$fusionReactor = new BuildingObject();
$fusionReactor->id = 12;
$fusionReactor->title = 'Fusion Reactor';
$fusionReactor->machine_name = 'fusion_plant';
$fusionReactor->description = 'The fusion reactor uses deuterium to produce energy.';
$fusionReactor->description_long = 'In fusion power plants, hydrogen nuclei are fused into helium nuclei under enormous temperature and pressure, releasing tremendous amounts of energy. For each gram of Deuterium consumed, up to 41,32*10^-13 Joule of energy can be produced; with 1 g you are able to produce 172 MWh energy.

Larger reactor complexes use more deuterium and can produce more energy per hour. The energy effect could be increased by researching energy technology.

The energy production of the fusion plant is calculated like that:
30 * [Level Fusion Plant] * (1,05 + [Level Energy Technology] * 0,01) ^ [Level Fusion Plant]';

$fusionReactor->price = new GameObjectPrice(900, 360, 180, 0, 1.8);
$fusionReactor->requirements = [
new GameObjectRequirement('deuterium_synthesizer', 5),
new GameObjectRequirement('research_lab', 5),
];
$fusionReactor->production = new GameObjectProduction();
$fusionReactor->production->deuterium = 'return - (10 * $building_level * pow(1.1, $building_level));';
$fusionReactor->production->energy = 'return (30 * $building_level * pow((1.05 + $energy_technology_level * 0.01), $building_level)) * (0.1 * $building_percentage);';

$fusionReactor->assets = new GameObjectAssets();
$fusionReactor->assets->imgMicro = 'fusion_plant_micro.jpg';
$fusionReactor->assets->imgSmall = 'fusion_plant_small.jpg';
$buildingObjectsNew[] = $fusionReactor;
// --------------------

// --- Metal Storage ---
$metalStorage = new BuildingObject();
$metalStorage->id = 22;
$metalStorage->title = 'Metal Storage';
$metalStorage->machine_name = 'metal_store';
$metalStorage->description = 'Provides storage for excess metal.';
$metalStorage->description_long = 'This giant storage facility is used to store metal ore. Each level of upgrading increases the amount of metal ore that can be stored. If the stores are full, no further metal will be mined.

The Metal Storage protects a certain percentage of the mine`s daily production (max. 10 percent).';

$metalStorage->price = new GameObjectPrice(1000, 0, 0, 0, 2);
$metalStorage->storage = new GameObjectStorage();
$metalStorage->storage->metal = 'return 5000 * floor(2.5 * exp(20 * $building_level / 33));';

$metalStorage->assets = new GameObjectAssets();
$metalStorage->assets->imgMicro = 'metal_store_micro.jpg';
$metalStorage->assets->imgSmall = 'metal_store_small.jpg';
$buildingObjectsNew[] = $metalStorage;
// --------------------

// --- Crystal Storage ---
$crystalStorage = new BuildingObject();
$crystalStorage->id = 23;
$crystalStorage->title = 'Crystal Storage';
$crystalStorage->machine_name = 'crystal_store';
$crystalStorage->description = 'Provides storage for excess crystal.';

$crystalStorage->description_long = 'The unprocessed crystal will be stored in these giant storage halls in the meantime. With each level of upgrade, it increases the amount of crystal can be stored. If the crystal stores are full, no further crystal will be mined.

The Crystal Storage protects a certain percentage of the mine`s daily production (max. 10 percent).';
$crystalStorage->price = new GameObjectPrice(1000, 500, 0, 0, 2);
$crystalStorage->storage = new GameObjectStorage();
$crystalStorage->storage->crystal = 'return 5000 * floor(2.5 * exp(20 * $building_level / 33));';

$crystalStorage->assets = new GameObjectAssets();
$crystalStorage->assets->imgMicro = 'crystal_store_micro.jpg';
$crystalStorage->assets->imgSmall = 'crystal_store_small.jpg';
$buildingObjectsNew[] = $crystalStorage;
// --------------------

// --- Deuterium Tank ---
$deuteriumTank = new BuildingObject();
$deuteriumTank->id = 24;
$deuteriumTank->title = 'Deuterium Tank';
$deuteriumTank->machine_name = 'deuterium_store';
$deuteriumTank->description = 'Giant tanks for storing newly-extracted deuterium.';
$deuteriumTank->description_long = 'The Deuterium tank is for storing newly-synthesized deuterium. Once it is processed by the synthesizer, it is piped into this tank for later use. With each upgrade of the tank, the total storage capacity is increased. Once the capacity is reached, no further Deuterium will be synthesized.

The Deuterium Tank protects a certain percentage of the synthesizer`s daily production (max. 10 percent).';

$deuteriumTank->price = new GameObjectPrice(1000, 1000, 0, 0, 2);
$deuteriumTank->storage = new GameObjectStorage();
$deuteriumTank->storage->deuterium = 'return 5000 * floor(2.5 * exp(20 * $building_level / 33));';

$deuteriumTank->assets = new GameObjectAssets();
$deuteriumTank->assets->imgMicro = 'deuterium_store_micro.jpg';
$deuteriumTank->assets->imgSmall = 'deuterium_store_small.jpg';
$buildingObjectsNew[] = $deuteriumTank;
// --------------------

return $buildingObjectsNew;
}
}
Loading
Loading