From d8d6b34e900b16b3f38bff8866de261b062f68ea Mon Sep 17 00:00:00 2001 From: Keith Solomon Date: Tue, 10 Feb 2026 07:19:26 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9E=20fix:=20phpcs=20issue=20cleanup?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- buy-ships.php | 6 +- lib/project-config.php | 11 +- lib/spacetraders-api-exception.php | 26 ++-- lib/spacetraders-api.php | 11 +- lib/spacetraders-storage.php | 21 +-- mining-fleet.php | 15 +- ship-details.php | 216 ++++++++++++++--------------- 7 files changed, 152 insertions(+), 154 deletions(-) diff --git a/buy-ships.php b/buy-ships.php index 36733b8..e5eb05b 100644 --- a/buy-ships.php +++ b/buy-ships.php @@ -47,11 +47,7 @@ if (! isset( $tokenError ) ) { try { if (! isset( $tokenError ) ) { - if ( - $_SERVER['REQUEST_METHOD'] === 'POST' && - isset( $_POST['ship_type'] ) && - isset( $_POST['waypoint_symbol'] ) - ) { + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['ship_type'] ) && isset( $_POST['waypoint_symbol'] )) { $shipType = trim( (string) $_POST['ship_type'] ); $waypointSymbol = trim( (string) $_POST['waypoint_symbol'] ); diff --git a/lib/project-config.php b/lib/project-config.php index 49418fa..6b855cf 100644 --- a/lib/project-config.php +++ b/lib/project-config.php @@ -1,8 +1,15 @@ + * @license MIT License + * @version GIT: + * @link https://git.keithsolomon.net/keith/Spacetraders */ return array( diff --git a/lib/spacetraders-api-exception.php b/lib/spacetraders-api-exception.php index 0885257..c3fc1ee 100644 --- a/lib/spacetraders-api-exception.php +++ b/lib/spacetraders-api-exception.php @@ -1,24 +1,22 @@ - * @license MIT License - * @link https://github.com/your-repo/spacetraders - */ - -/** - * Custom exception class for Spacetraders API related errors. + * Spacetraders API Client Library - Exception class * * This exception is thrown when API calls to the Spacetraders service * encounter errors such as network issues, invalid responses, authentication * failures, or other API-specific problems. * + * @category Exception + * @package SpacetradersAPI + * @author Keith Solomon + * @license MIT License + * @version GIT: + * @link https://git.keithsolomon.net/keith/Spacetraders + */ + +/** + * Custom exception class for Spacetraders API related errors. + * * @extends RuntimeException */ class SpacetradersApiException extends RuntimeException { diff --git a/lib/spacetraders-api.php b/lib/spacetraders-api.php index 6726be5..669a1bb 100644 --- a/lib/spacetraders-api.php +++ b/lib/spacetraders-api.php @@ -7,11 +7,12 @@ * It includes methods for authentication, making API requests, and handling responses, * making it easier to integrate Spacetraders into your applications or scripts. * - * @package SpacetradersAPI - * @author Keith Solomon - * @license MIT License - * @version GIT: - * @link https://spacetraders.io + * @category API + * @package SpacetradersAPI + * @author Keith Solomon + * @license MIT License + * @version GIT: + * @link https://git.keithsolomon.net/keith/Spacetraders */ require_once __DIR__ . '/spacetraders-api-exception.php'; diff --git a/lib/spacetraders-storage.php b/lib/spacetraders-storage.php index 8885ea5..4db53b4 100644 --- a/lib/spacetraders-storage.php +++ b/lib/spacetraders-storage.php @@ -1,18 +1,19 @@ - * @license MIT License - * @link https://git.keithsolomon.net/keith/Spacetraders + * SQLite storage for configuration and API cache. + * + * @category Storage + * @package SpacetradersAPI + * @author Keith Solomon + * @license MIT License + * @version GIT: + * @link https://git.keithsolomon.net/keith/Spacetraders */ /** - * Spacetraders SQLite storage for configuration and API cache. - * - * @package SpacetradersAPI + * Storage for configuration and API cache. */ class SpacetradersStorage { /** @@ -45,7 +46,7 @@ class SpacetradersStorage { * * @return void */ - private function _initializeSchema(): void { + private function _initializeSchema(): void { // phpcs:ignore $this->db->exec( 'CREATE TABLE IF NOT EXISTS settings ( setting_key TEXT PRIMARY KEY, diff --git a/mining-fleet.php b/mining-fleet.php index 21549f6..481f4ab 100644 --- a/mining-fleet.php +++ b/mining-fleet.php @@ -18,7 +18,7 @@ require_once __DIR__ . '/lib/spacetraders-storage.php'; * * @return array> */ -function spacetraders_filter_mining_ships( array $ships ): array { +function filterMiningShips( array $ships ): array { return array_values( array_filter( $ships, @@ -76,7 +76,7 @@ try { $agent = $agentResponse['data'] ?? $agentResponse; $ships = $shipsResponse['data'] ?? $shipsResponse; $contracts = $contractsResponse['data'] ?? $contractsResponse; - $miningShips = spacetraders_filter_mining_ships( $ships ); + $miningShips = filterMiningShips( $ships ); $activeContracts = array_values( array_filter( (array) $contracts, @@ -291,7 +291,7 @@ try { $contractsResponse = $client->listMyContracts(); $ships = $shipsResponse['data'] ?? $shipsResponse; $contracts = $contractsResponse['data'] ?? $contractsResponse; - $miningShips = spacetraders_filter_mining_ships( $ships ); + $miningShips = filterMiningShips( $ships ); $activeContracts = array_values( array_filter( (array) $contracts, @@ -302,12 +302,7 @@ try { ); } - if ( - $_SERVER['REQUEST_METHOD'] === 'POST' && - isset( $_POST['ship_action'] ) && - in_array( (string) $_POST['ship_action'], array( 'sell_ship_cargo', 'jettison_ship_cargo' ), true ) && - isset( $_POST['ship_symbol'] ) - ) { + if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['ship_action'] ) && in_array( (string) $_POST['ship_action'], array( 'sell_ship_cargo', 'jettison_ship_cargo' ), true ) && isset( $_POST['ship_symbol'] )) { $shipAction = (string) $_POST['ship_action']; $sellShipSymbol = trim( (string) $_POST['ship_symbol'] ); @@ -355,7 +350,7 @@ try { $shipsResponse = $client->listMyShips(); $ships = $shipsResponse['data'] ?? $shipsResponse; - $miningShips = spacetraders_filter_mining_ships( $ships ); + $miningShips = filterMiningShips( $ships ); } catch (SpacetradersApiException $e) { $errorMessage = $sellShipSymbol . ': ' . $e->getMessage(); } diff --git a/ship-details.php b/ship-details.php index 7e1e721..2066aab 100644 --- a/ship-details.php +++ b/ship-details.php @@ -57,129 +57,129 @@ try { if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset( $_POST['ship_action'] ) ) { $action = (string) $_POST['ship_action']; switch ($action) { - case 'orbit': - $client->orbitShip( $shipSymbol ); - $statusMessage = 'Ship set to orbit.'; - break; - case 'dock': + case 'orbit': + $client->orbitShip( $shipSymbol ); + $statusMessage = 'Ship set to orbit.'; + break; + case 'dock': + $client->dockShip( $shipSymbol ); + $statusMessage = 'Ship docked.'; + break; + case 'extract': + $client->extractResources( $shipSymbol ); + $statusMessage = 'Resource extraction started.'; + break; + case 'survey': + $client->surveyWaypoint( $shipSymbol ); + $statusMessage = 'Survey completed.'; + break; + case 'siphon': + $client->siphonResources( $shipSymbol ); + $statusMessage = 'Siphon action completed.'; + break; + case 'refuel': + $client->refuelShip( $shipSymbol ); + $statusMessage = 'Ship refueled.'; + break; + case 'sell_all_cargo': + $shipResponse = $client->getShip( $shipSymbol ); + $shipData = $shipResponse['data'] ?? array(); + $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); + + if ($shipStatus === 'IN_TRANSIT' ) { + throw new SpacetradersApiException( 'Ship is in transit and cannot sell cargo right now.' ); + } + + if ($shipStatus !== 'DOCKED' ) { $client->dockShip( $shipSymbol ); - $statusMessage = 'Ship docked.'; - break; - case 'extract': - $client->extractResources( $shipSymbol ); - $statusMessage = 'Resource extraction started.'; - break; - case 'survey': - $client->surveyWaypoint( $shipSymbol ); - $statusMessage = 'Survey completed.'; - break; - case 'siphon': - $client->siphonResources( $shipSymbol ); - $statusMessage = 'Siphon action completed.'; - break; - case 'refuel': - $client->refuelShip( $shipSymbol ); - $statusMessage = 'Ship refueled.'; - break; - case 'sell_all_cargo': - $shipResponse = $client->getShip( $shipSymbol ); - $shipData = $shipResponse['data'] ?? array(); - $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); - - if ($shipStatus === 'IN_TRANSIT' ) { - throw new SpacetradersApiException( 'Ship is in transit and cannot sell cargo right now.' ); - } - - if ($shipStatus !== 'DOCKED' ) { - $client->dockShip( $shipSymbol ); - } - - $inventory = (array) ( $shipData['cargo']['inventory'] ?? array() ); - $soldItems = 0; - foreach ( $inventory as $item ) { - $tradeSymbol = (string) ( $item['symbol'] ?? '' ); - $units = (int) ( $item['units'] ?? 0 ); - if ($tradeSymbol === '' || $units <= 0 ) { - continue; - } - - try { - $client->sellCargo( $shipSymbol, $tradeSymbol, $units ); - $soldItems++; - } catch (SpacetradersApiException $e) { - // Continue selling other items. - } - } - - $statusMessage = 'Attempted to sell all cargo item types. Sold: ' . $soldItems . '.'; - break; - case 'sell_cargo_item': - $tradeSymbol = trim( (string) ( $_POST['trade_symbol'] ?? '' ) ); - $units = (int) ( $_POST['units'] ?? 0 ); + } + $inventory = (array) ( $shipData['cargo']['inventory'] ?? array() ); + $soldItems = 0; + foreach ( $inventory as $item ) { + $tradeSymbol = (string) ( $item['symbol'] ?? '' ); + $units = (int) ( $item['units'] ?? 0 ); if ($tradeSymbol === '' || $units <= 0 ) { - throw new SpacetradersApiException( 'Trade symbol and units are required to sell cargo.' ); + continue; } - $shipResponse = $client->getShip( $shipSymbol ); - $shipData = $shipResponse['data'] ?? array(); - $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); - - if ($shipStatus === 'IN_TRANSIT' ) { - throw new SpacetradersApiException( 'Ship is in transit and cannot sell cargo right now.' ); + try { + $client->sellCargo( $shipSymbol, $tradeSymbol, $units ); + $soldItems++; + } catch (SpacetradersApiException $e) { + // Continue selling other items. } + } - if ($shipStatus !== 'DOCKED' ) { - $client->dockShip( $shipSymbol ); - } + $statusMessage = 'Attempted to sell all cargo item types. Sold: ' . $soldItems . '.'; + break; + case 'sell_cargo_item': + $tradeSymbol = trim( (string) ( $_POST['trade_symbol'] ?? '' ) ); + $units = (int) ( $_POST['units'] ?? 0 ); - $client->sellCargo( $shipSymbol, $tradeSymbol, $units ); - $statusMessage = 'Sold ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.'; - break; - case 'jettison_all_cargo': - $shipResponse = $client->getShip( $shipSymbol ); - $shipData = $shipResponse['data'] ?? array(); - $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); - if ($shipStatus === 'IN_TRANSIT' ) { - throw new SpacetradersApiException( 'Ship is in transit and cannot jettison cargo right now.' ); - } + if ($tradeSymbol === '' || $units <= 0 ) { + throw new SpacetradersApiException( 'Trade symbol and units are required to sell cargo.' ); + } - $inventory = (array) ( $shipData['cargo']['inventory'] ?? array() ); - $jettisonedItems = 0; - foreach ( $inventory as $item ) { - $tradeSymbol = (string) ( $item['symbol'] ?? '' ); - $units = (int) ( $item['units'] ?? 0 ); - if ($tradeSymbol === '' || $units <= 0 ) { - continue; - } + $shipResponse = $client->getShip( $shipSymbol ); + $shipData = $shipResponse['data'] ?? array(); + $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); - try { - $client->jettisonCargo( $shipSymbol, $tradeSymbol, $units ); - $jettisonedItems++; - } catch (SpacetradersApiException $e) { - // Continue attempting the rest. - } - } + if ($shipStatus === 'IN_TRANSIT' ) { + throw new SpacetradersApiException( 'Ship is in transit and cannot sell cargo right now.' ); + } - $statusMessage = 'Attempted to jettison all cargo item types. Jettisoned: ' . $jettisonedItems . '.'; - break; - case 'jettison_cargo_item': - $tradeSymbol = trim( (string) ( $_POST['trade_symbol'] ?? '' ) ); - $units = (int) ( $_POST['units'] ?? 0 ); + if ($shipStatus !== 'DOCKED' ) { + $client->dockShip( $shipSymbol ); + } + + $client->sellCargo( $shipSymbol, $tradeSymbol, $units ); + $statusMessage = 'Sold ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.'; + break; + case 'jettison_all_cargo': + $shipResponse = $client->getShip( $shipSymbol ); + $shipData = $shipResponse['data'] ?? array(); + $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); + if ($shipStatus === 'IN_TRANSIT' ) { + throw new SpacetradersApiException( 'Ship is in transit and cannot jettison cargo right now.' ); + } + + $inventory = (array) ( $shipData['cargo']['inventory'] ?? array() ); + $jettisonedItems = 0; + foreach ( $inventory as $item ) { + $tradeSymbol = (string) ( $item['symbol'] ?? '' ); + $units = (int) ( $item['units'] ?? 0 ); if ($tradeSymbol === '' || $units <= 0 ) { - throw new SpacetradersApiException( 'Trade symbol and units are required to jettison cargo.' ); + continue; } - $shipResponse = $client->getShip( $shipSymbol ); - $shipData = $shipResponse['data'] ?? array(); - $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); - if ($shipStatus === 'IN_TRANSIT' ) { - throw new SpacetradersApiException( 'Ship is in transit and cannot jettison cargo right now.' ); + try { + $client->jettisonCargo( $shipSymbol, $tradeSymbol, $units ); + $jettisonedItems++; + } catch (SpacetradersApiException $e) { + // Continue attempting the rest. } + } - $client->jettisonCargo( $shipSymbol, $tradeSymbol, $units ); - $statusMessage = 'Jettisoned ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.'; - break; + $statusMessage = 'Attempted to jettison all cargo item types. Jettisoned: ' . $jettisonedItems . '.'; + break; + case 'jettison_cargo_item': + $tradeSymbol = trim( (string) ( $_POST['trade_symbol'] ?? '' ) ); + $units = (int) ( $_POST['units'] ?? 0 ); + if ($tradeSymbol === '' || $units <= 0 ) { + throw new SpacetradersApiException( 'Trade symbol and units are required to jettison cargo.' ); + } + + $shipResponse = $client->getShip( $shipSymbol ); + $shipData = $shipResponse['data'] ?? array(); + $shipStatus = (string) ( $shipData['nav']['status'] ?? '' ); + if ($shipStatus === 'IN_TRANSIT' ) { + throw new SpacetradersApiException( 'Ship is in transit and cannot jettison cargo right now.' ); + } + + $client->jettisonCargo( $shipSymbol, $tradeSymbol, $units ); + $statusMessage = 'Jettisoned ' . number_format( $units ) . ' units of ' . $tradeSymbol . '.'; + break; } if ($statusMessage !== '' ) { @@ -284,7 +284,7 @@ try { - 0 ) : ?> + 0) : ?>