Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
41e8f78
Update CI workflow to use specific action versions and improve PHP setup
nemuvski Jul 3, 2026
819daf1
Refactor CI workflow to set PHP version via environment variable and …
nemuvski Jul 3, 2026
7dba0b9
Enhance CI workflow by consolidating formatter steps, updating PHPSta…
nemuvski Jul 3, 2026
de673c4
Update CI workflow to include PHP 8.5 in the testing matrix
nemuvski Jul 3, 2026
ed4aefc
Refactor CI workflow to run PHP CS Fixer on src and tests directories…
nemuvski Jul 3, 2026
7cca9bf
Update CI workflow to set timeout for linting and testing jobs
nemuvski Jul 3, 2026
d5bc4b8
Refactor CI workflow to remove PHPStan and PHPUnit from tools list, a…
nemuvski Jul 3, 2026
8a25f42
Reduce timeout for linting and testing jobs in CI workflow from 10 to…
nemuvski Jul 3, 2026
bdff50f
Add PHP CS Fixer configuration file and simplify CI formatter step
nemuvski Jul 3, 2026
620e9b6
Update PHP CS Fixer configuration to simplify trailing comma rule
nemuvski Jul 3, 2026
c846e1e
Add operator linebreak rule to PHP CS Fixer configuration
nemuvski Jul 3, 2026
4e26554
Add devcontainer configuration for PHP development environment
nemuvski Jul 3, 2026
2a86af1
Update PHPStan version to 2.0, add PHPStan configuration file, and ad…
nemuvski Jul 3, 2026
7a2e42b
Refactor Client class to use typed properties and return types, and u…
nemuvski Jul 3, 2026
81f6dc3
Merge pull request #3 from microcmsio/devcontainer
nemuvski Jul 3, 2026
9e3dc0b
Enhance Client class method signatures by adding return type annotati…
nemuvski Jul 3, 2026
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
17 changes: 17 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "microcms-php-sdk",
"image": "mcr.microsoft.com/devcontainers/php:8.5",
"features": {
"ghcr.io/devcontainers/features/github-cli:1": {}
},
"customizations": {
"vscode": {
"extensions": [
"xdebug.php-debug",
"bmewburn.vscode-intelephense-client",
"junstyle.php-cs-fixer"
]
}
},
"postCreateCommand": "composer install"
}
65 changes: 38 additions & 27 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,61 @@ on:
pull_request:
branches: [ main ]

jobs:
tests:
env:
MAIN_PHP_VERSION: '8.5'

jobs:
lint:
runs-on: ubuntu-latest

strategy:
matrix:
php-versions: ['7.3', '7.4', '8.0']

timeout-minutes: 5
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@master
uses: step-security/setup-php@0b4c3f57a1fb50d5cc8172a9700f35b97b3b5d97 # v2.37.0
with:
php-version: ${{ matrix.php-versions }}
php-version: ${{ env.MAIN_PHP_VERSION }}
tools: composer, php-cs-fixer
env:
fail-fast: true

- name: Validate composer.json and composer.lock
run: composer validate --strict

- name: Cache Composer packages
id: composer-cache
uses: actions/cache@v2
with:
path: vendor
key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-php-

- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run formatter (src/)
uses: docker://oskarstark/php-cs-fixer-ga
- name: Run formatter
run: php-cs-fixer fix --diff --dry-run

- name: Run linter
run: vendor/bin/phpstan analyse

tests:
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
matrix:
php-versions: ['7.4', '8.5']

steps:
- uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
with:
args: --diff --dry-run src/
persist-credentials: false

- name: Run formatter (tests/)
uses: docker://oskarstark/php-cs-fixer-ga
- name: Setup PHP
uses: step-security/setup-php@0b4c3f57a1fb50d5cc8172a9700f35b97b3b5d97 # v2.37.0
with:
args: --diff --dry-run tests/
php-version: ${{ matrix.php-versions }}
tools: composer
env:
fail-fast: true

- name: Run linter
run: vendor/bin/phpstan analyse --level 5 src/ tests/
- name: Install dependencies
run: composer install --prefer-dist --no-progress

- name: Run test suite
run: vendor/bin/phpunit tests/
12 changes: 12 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$finder = (new PhpCsFixer\Finder())
->in([__DIR__ . '/src', __DIR__ . '/tests']);

return (new PhpCsFixer\Config())
->setRules([
'@PER-CS' => true,
'trailing_comma_in_multiline' => false,
'operator_linebreak' => ['position' => 'end'],
])
->setFinder($finder);
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
],
"require-dev": {
"psy/psysh": "@stable",
"phpstan/phpstan": "^0.12.99",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^9.5"
}
}
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: 8
paths:
- src
- tests
45 changes: 38 additions & 7 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

class Client
{
private $serviceDomain;
private $apiKey;
private string $serviceDomain;
private string $apiKey;

private $client;
private \GuzzleHttp\Client $client;

public function __construct(string $serviceDomain, string $apiKey, \GuzzleHttp\ClientInterface $client = null)
public function __construct(string $serviceDomain, string $apiKey, ?\GuzzleHttp\Client $client = null)
{
$this->serviceDomain = $serviceDomain;
$this->apiKey = $apiKey;
Expand All @@ -21,6 +21,11 @@ public function __construct(string $serviceDomain, string $apiKey, \GuzzleHttp\C
}
}

/**
* @param array<string, mixed> $options
*
* @return mixed
*/
public function list(string $endpoint, array $options = [])
{
$path = $endpoint;
Expand All @@ -33,6 +38,11 @@ public function list(string $endpoint, array $options = [])
return json_decode($response->getBody());
}

/**
* @param array<string, mixed> $options
*
* @return mixed
*/
public function get(string $endpoint, string $contentId = "", array $options = [])
{
$path = $contentId ? implode("/", [$endpoint, $contentId]) : $endpoint;
Expand All @@ -45,6 +55,12 @@ public function get(string $endpoint, string $contentId = "", array $options = [
return json_decode($response->getBody());
}

/**
* @param array<string, mixed> $body
* @param array<string, mixed> $options
*
* @return mixed
*/
public function create(string $endpoint, array $body = [], array $options = [])
{
if (array_key_exists("id", $body)) {
Expand All @@ -66,6 +82,11 @@ public function create(string $endpoint, array $body = [], array $options = [])
return json_decode($response->getBody());
}

/**
* @param array<string, mixed> $body
*
* @return mixed
*/
public function update(string $endpoint, array $body = [])
{
$response = $this->client->patch(
Expand All @@ -83,13 +104,18 @@ function ($v, $k) {
return json_decode($response->getBody());
}

public function delete(string $endpoint, string $id)
public function delete(string $endpoint, string $id): void
{
$path = implode("/", [$endpoint, $id]);
$this->client->delete($path, $this->buildOption());
}

private function buildOption(array $option = [])
/**
* @param array<string, mixed> $option
*
* @return array<string, mixed>
*/
private function buildOption(array $option = []): array
{
return array_merge(
[
Expand All @@ -102,7 +128,12 @@ private function buildOption(array $option = [])
);
}

private function buildQuery(array $options)
/**
* @param array<string, mixed> $options
*
* @return array<string, mixed>
*/
private function buildQuery(array $options): array
{
return array_filter(
[
Expand Down
9 changes: 6 additions & 3 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@

final class ClientTest extends TestCase
{
private $handlerStack;
private $mock;
private HandlerStack $handlerStack;
private MockHandler $mock;

/** @var array<int, array<string, mixed>> */
private $container;

protected function setUp(): void
{
$this->handlerStack = HandlerStack::create();
$this->container = [];
$container = &$this->container;

$this->mock = new MockHandler([]);
$this->handlerStack->setHandler($this->mock);

$history = Middleware::history($this->container);
$history = Middleware::history($container);
$this->handlerStack->push($history);
}

Expand Down