Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
45 changes: 38 additions & 7 deletions .github/workflows/deploy-to-github-pages.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,3 @@ $RECYCLE.BIN/

# End of https://www.gitignore.io/api/git,macos,windows,composer,phpstorm,visualstudiocode
/cache
/doctum.php
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ composer require cable8mm/good-code
Visit repository - <https://github.com/cable8mm/aipro>

```php
<?php

use App\Models\OptionGood;
use Cable8mm\GoodCode\Enums\GoodCodeType;
use Cable8mm\GoodCode\GoodCode;

/**
* For option products, retrieve the master_code of the option and update it.
*/
Expand All @@ -52,6 +58,12 @@ if (GoodCodeType::of($this->data->get('sellerGoodsCd')) == GoodCodeType::OPTION)
```

```php
<?php

use Cable8mm\GoodCode\Enums\GoodCodeType;
use Cable8mm\GoodCode\GoodCode;
use Cable8mm\GoodCode\ValueObjects\SetGood;

/**
* For composite and gift products, retrieve the set product and update the master_code.
*/
Expand All @@ -76,6 +88,9 @@ if (

```php
<?php

use Cable8mm\GoodCode\GoodCode;

print GoodCode::of('SET7369x4zz4235x6')->value();
//=> ['7369'=>4,'4235'=>6]

Expand All @@ -86,6 +101,10 @@ print GoodCode::setCodeOf(['1234' => 2, '5678' => 1,])->code();
#### `complex-code`

```php
<?php

use Cable8mm\GoodCode\GoodCode;

print GoodCode::of('COM10', callback: function ($key) {
$a = [ 10 => '123'];

Expand All @@ -97,6 +116,10 @@ print GoodCode::of('COM10', callback: function ($key) {
#### `gift-code`

```php
<?php

use Cable8mm\GoodCode\GoodCode;

print GoodCode::of('GIF11', callback: function ($key) {
$a = [
11 => '456',
Expand All @@ -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
<?php

use Cable8mm\GoodCode\GoodCode;

print GoodCode::of($optionCode, option: $optionName, callback: function ($key, $option) {
$a = [
10 => [
Expand All @@ -134,6 +161,10 @@ print GoodCode::of($optionCode, option: $optionName, callback: function ($key, $
### Special value object - `SetGood`

```php
<?php

use Cable8mm\GoodCode\ValueObjects\SetGood;

print SetGood::of('SET43x3zz253x3')->goods();
//=> ['43' => 3, '253' => 3]

Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
26 changes: 26 additions & 0 deletions doctum.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

use Doctum\Doctum;
use Doctum\RemoteRepository\GitHubRemoteRepository;
use Symfony\Component\Finder\Finder;

$dir = getcwd().'/src';
$iterator = Finder::create()
->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',
],
]);
15 changes: 15 additions & 0 deletions src/Enums/GoodCodeType.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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));
Expand Down
18 changes: 18 additions & 0 deletions src/GoodCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,43 @@
*/
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,
) {
$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;
Expand Down
43 changes: 38 additions & 5 deletions src/ValueObjects/SetGood.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string,string> 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();
Expand All @@ -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)) {
Expand All @@ -47,10 +67,10 @@ public static function of(string $code): SetGood
/**
* Create SetGood instance from key-value set code array.
*
* @param array<string,string> $setCodes key-value set code array
* @param array<string,int> $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
{
Expand All @@ -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;
}
Expand Down