diff --git a/.github/workflows/deploy-to-github-pages.yml b/.github/workflows/deploy-to-github-pages.yml index 2c8dbcb..db10656 100644 --- a/.github/workflows/deploy-to-github-pages.yml +++ b/.github/workflows/deploy-to-github-pages.yml @@ -1,13 +1,44 @@ name: deploy-to-github-pages on: - release: - types: [released] + workflow_call: + push: + branches: ["main"] -permissions: {} +permissions: + contents: read + pages: write + id-token: write + +# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. +# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. +concurrency: + group: "pages" + cancel-in-progress: false jobs: - publish-pages: - permissions: - contents: write - uses: cable8mm/.github/.github/workflows/deploy-to-github-pages.yml@main + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Pages + uses: actions/configure-pages@v5 + - name: build doctum docs + uses: sudo-bot/action-doctum@v5 + with: + config-file: doctum.php + method: "update" + # (optional) defaults to '--output-format=github --no-ansi --no-progress -v' + cli-args: "--output-format=github --no-ansi --no-progress -v" + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + # Upload entire repository + path: ./build + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.gitignore b/.gitignore index 460742f..9fd5ed8 100644 --- a/.gitignore +++ b/.gitignore @@ -183,4 +183,3 @@ $RECYCLE.BIN/ # End of https://www.gitignore.io/api/git,macos,windows,composer,phpstorm,visualstudiocode /cache -/doctum.php diff --git a/README.md b/README.md index d74be81..5d8721e 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,12 @@ composer require cable8mm/good-code Visit repository - ```php +data->get('sellerGoodsCd')) == GoodCodeType::OPTION) ``` ```php +value(); //=> ['7369'=>4,'4235'=>6] @@ -86,6 +101,10 @@ print GoodCode::setCodeOf(['1234' => 2, '5678' => 1,])->code(); #### `complex-code` ```php + '123']; @@ -97,6 +116,10 @@ print GoodCode::of('COM10', callback: function ($key) { #### `gift-code` ```php + '456', @@ -113,6 +136,10 @@ print GoodCode::of('GIF11', callback: function ($key) { > `option-code` are matching with **both** `option-code` **and** `option-good-option` name. Unfortunately all of online shops like Coupang and 11st have not send any key for option to sellers. ```php + [ @@ -134,6 +161,10 @@ print GoodCode::of($optionCode, option: $optionName, callback: function ($key, $ ### Special value object - `SetGood` ```php +goods(); //=> ['43' => 3, '253' => 3] diff --git a/composer.json b/composer.json index 3cdd0f0..2161fef 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,7 @@ "test": "./vendor/bin/phpunit tests", "lint": "./vendor/bin/pint", "inspect": "./vendor/bin/pint --test", - "api-doc": "doctum.phar update doctum.php --output-format=github --no-ansi --no-progress", - "api-parse": "doctum.phar parse doctum.php --output-format=github -v" + "apidoc": "doctum.phar update doctum.php --output-format=github --no-ansi --no-progress", + "opendoc": "open build/index.html" } } \ No newline at end of file diff --git a/doctum.php b/doctum.php new file mode 100644 index 0000000..23f878b --- /dev/null +++ b/doctum.php @@ -0,0 +1,26 @@ +files() + ->name('*.php') + ->exclude('Resources') + ->exclude('Tests') + ->in($dir); + +return new Doctum($iterator, [ + 'title' => 'The cable8mm/good-code API', + 'source_dir' => dirname($dir).'/', + 'remote_repository' => new GitHubRemoteRepository('cable8mm/good-code', dirname($dir)), + 'footer_link' => [ + 'href' => 'https://github.com/cable8mm/good-code', + 'target' => '_blank', + 'before_text' => 'You can refer', + 'link_text' => 'cable8mm/good-code', // Required if the href key is set + 'after_text' => 'repository', + ], +]); diff --git a/src/Enums/GoodCodeType.php b/src/Enums/GoodCodeType.php index 20f852e..5c896e9 100644 --- a/src/Enums/GoodCodeType.php +++ b/src/Enums/GoodCodeType.php @@ -10,6 +10,13 @@ enum GoodCodeType case GIFT; case OPTION; + /** + * Get prefix of GoodCodeType. + * + * @return string The method returns the prefix of the GoodCodeType + * + * @example GoodCodeType::GIFT->prefix() => 'GIF' + */ public function prefix(): string { return match ($this) { @@ -21,6 +28,14 @@ public function prefix(): string }; } + /** + * Get GoodCodeType by code. + * + * @param string $code The good code + * @return GoodCodeType The method returns the `GoodCodeType` object + * + * @example GoodCodeType::of('OPT2231433') => GoodCodeType::OPTION + */ public static function of(string $code): GoodCodeType { $prefix = strtoupper(substr($code, 0, 3)); diff --git a/src/GoodCode.php b/src/GoodCode.php index b0b5f12..00643dc 100644 --- a/src/GoodCode.php +++ b/src/GoodCode.php @@ -11,8 +11,17 @@ */ class GoodCode { + /** + * @var GoodCodeType The type of the code + */ private GoodCodeType $type; + /** + * Constructor. + * + * @param string $code The code + * @param \Cable8mm\GoodCode\Enums\GoodCodeType $originType The type of the code + */ public function __construct( private string $code, private GoodCodeType $originType, @@ -20,16 +29,25 @@ public function __construct( $this->type = GoodCodeType::of($code); } + /** + * Gets the `code` property + */ public function code(): string { return $this->code; } + /** + * Gets the `originalType` property + */ public function originalType(): GoodCodeType { return $this->originType; } + /** + * Gets the `type` property + */ public function type(): GoodCodeType { return $this->type; diff --git a/src/ValueObjects/SetGood.php b/src/ValueObjects/SetGood.php index 9edfd12..fc6748c 100644 --- a/src/ValueObjects/SetGood.php +++ b/src/ValueObjects/SetGood.php @@ -3,17 +3,31 @@ namespace Cable8mm\GoodCode\ValueObjects; use Cable8mm\GoodCode\Enums\GoodCodeType; -use Cable8mm\GoodCode\GoodCode; use InvalidArgumentException; +use Stringable; -class SetGood +class SetGood implements Stringable { + /** + * The delimiter for multiple good code + */ const DELIMITER = 'zz'; + /** + * The delimiter for good count + */ const DELIMITER_COUNT = 'x'; + /** + * @var array array of good code and count + */ private array $goods; + /** + * Constructor. + * + * @param string $code The name of the good code + */ private function __construct(private readonly string $code) { $this->pipe(); @@ -35,6 +49,12 @@ private function pipe(): void } } + /** + * Create SetGood instance from code. + * + * @param string $code The set code string + * @return SetGood The method returns SetGood instance with the SetCode string + */ public static function of(string $code): SetGood { if (! preg_match('/^'.GoodCodeType::SET->prefix().'/i', $code)) { @@ -47,10 +67,10 @@ public static function of(string $code): SetGood /** * Create SetGood instance from key-value set code array. * - * @param array $setCodes key-value set code array + * @param array $setCodes key-value set code array * @return SetGood The method returns SetGood instance with the SetCode string * - * @example GoodCode::setCodeOf(['7369'=>4,'4235'=>6]) => SET7369x4zz42335x6 + * @example SetGood::ofArray(['7369'=>4,'4235'=>6]) => SET7369x4zz42335x6 */ public static function ofArray(array $setCodes): SetGood { @@ -61,17 +81,30 @@ public static function ofArray(array $setCodes): SetGood return static::of($code); } + /** + * Gets a `code` property. + * + * @return string The method returns `code` property + */ public function code(): string { return $this->code; } + /** + * Gets a `goods` property. + * + * @return array The method returns `goods` property + */ public function goods(): array { return $this->goods; } - public function toString(): string + /** + * Gets a string representation of the object. + */ + public function __toString(): string { return $this->code; }