velkuns/artifactsmmo-client

PHP Client for Artifacts MMO Game Code

2.0.0 2024-08-25 16:38 UTC

This package is auto-updated.

Last update: 2024-10-25 17:04:18 UTC


README

Current version Supported PHP version CI Quality Gate Status Coverage

Why?

This SDK / Client is a wrapper to call Artifacts MMO API. Each clients methods call and endpoint and return a Value Object as defined in OpenAPI Spec from Artifacts MMO API.

Artifacts MMO API Doc: https://api.artifactsmmo.com/docs/

When POST endpoint need a BODY, an Body* Value Object (VO) is required to call the endpoint. If any query param is available, you can also pass it to the endpoint (PHP doc is set for params with name in this case)

Installation

If you wish to install it in your project, require it via composer:

composer require velkuns/artifactsmmo-client

Usage

Usage:

<?php

declare(strict_types=1);

namespace Application;

use Eureka\Component\Curl\HttpClient;
use Nyholm\Psr7\Factory\Psr17Factory;
use Psr\Log\NullLogger;
use Velkuns\ArtifactsMMO\Client\Client;
use Velkuns\ArtifactsMMO\Client\MyClient;
use Velkuns\ArtifactsMMO\Config\ArtifactsMMOConfig;
use Velkuns\ArtifactsMMO\Request\RequestBuilder;
use Velkuns\ArtifactsMMO\VO\Body\BodyCrafting;
use Velkuns\ArtifactsMMO\VO\Body\BodyDestination;

require_once(__DIR__ . '/../vendor/autoload.php');

$token = ''; // Your token

//~ Config part
$config = new ArtifactsMMOConfig('api.artifactsmmo.com', 'https', $token);

//~ Client dependencies
$httpClient     = new HttpClient(userAgent: 'artifactsmmo-client-test/1.0');
$requestFactory = new Psr17Factory();
$uriFactory     = new Psr17Factory();
$requestBuilder = new RequestBuilder($requestFactory, $uriFactory, $config);
$logger         = new NullLogger();

//~ Client
$client = new Client($httpClient, $logger, $requestBuilder);


//~ Call endpoint and get Value Object with response data
$status = $client->getStatus(); // Get status (VO\Status);

echo "Server is $status->status\n";
echo "Number of characters online: $status->charactersOnline\n";

//~ Move a character
$myClient = new MyClient($httpClient, $logger, $requestBuilder);
$myClient->actionMove('character_name', new BodyDestination(1, 1));

//~ Crafting an item
$myClient->actionCrafting('character_name', new BodyCrafting('wooden_staff', 1));

Contributing

See the CONTRIBUTING file.

Install / update project

You can install project with the following command:

make install

And update with the following command:

make update

NB: For the components, the composer.lock file is not committed.

Testing & CI (Continuous Integration)

Tests

You can run tests (with coverage) on your side with following command:

make tests

You can run tests (with coverage) on your side with following command:

make integration

For prettier output (but without coverage), you can use the following command:

make testdox # run tests without coverage reports but with prettified output

Code Style

You also can run code style check with following commands:

make phpcs

You also can run code style fixes with following commands:

make phpcsf

Static Analysis

To perform a static analyze of your code (with phpstan, lvl 9 at default), you can use the following command:

make analyze

Minimal supported version:

make php-min-compatibility

Maximal supported version:

make php-max-compatibility

CI Simulation

And the last "helper" commands, you can run before commit and push, is:

make ci  

License

This project is licensed under the MIT License - see the LICENSE file for details