diff --git a/.dockerignore b/.dockerignore index 136dc06..c504dde 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,5 +1,6 @@ composer.phar /vendor/ -.idea/ +/.idea/ +/.git/ LICENSE README.md diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..1d7a8c6 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,22 @@ +name: Build +on: + push: + branches: + - master + pull_request: + +jobs: + build: + name: Build package + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + - name: Docker image + uses: docker/build-push-action@v1 + with: + registry: ghcr.io + username: sysbot-org + password: ${{ secrets.PAT }} + repository: sysbot-org/tgscraper + tags: latest \ No newline at end of file diff --git a/.github/workflows/delete.yml b/.github/workflows/delete.yml new file mode 100644 index 0000000..c8afe96 --- /dev/null +++ b/.github/workflows/delete.yml @@ -0,0 +1,17 @@ +name: Delete +on: + push: + branches: + - master + pull_request: + +jobs: + build: + name: Delete old packages + runs-on: ubuntu-latest + steps: + - name: Delete oldest package + uses: actions/delete-package-versions@v1 + with: + package-name: tgscraper + num-old-versions-to-delete: 1 \ No newline at end of file diff --git a/src/Common/SchemaExtractor.php b/src/Common/SchemaExtractor.php index 7a78f0b..6694127 100644 --- a/src/Common/SchemaExtractor.php +++ b/src/Common/SchemaExtractor.php @@ -47,7 +47,7 @@ class SchemaExtractor * @throws ChildNotFoundException */ #[ArrayShape(['description' => "string", 'table' => "mixed", 'extended_by' => "array"])] - private function parseNode(Dom\Node\AbstractNode $node): ?array + private static function parseNode(Dom\Node\AbstractNode $node): ?array { $description = ''; $table = null; diff --git a/src/Common/StubCreator.php b/src/Common/StubCreator.php index 6fb1691..1a4ee5c 100644 --- a/src/Common/StubCreator.php +++ b/src/Common/StubCreator.php @@ -24,6 +24,14 @@ class StubCreator * @var string */ private string $namespace; + /** + * @var array + */ + private array $abstractClasses = []; + /** + * @var array + */ + private array $extendedClasses = []; /** * StubCreator constructor. @@ -43,6 +51,16 @@ class StubCreator if (!is_array($this->schema['methods']) or !is_array($this->schema['types'])) { throw new InvalidArgumentException('Schema invalid'); } + foreach ($this->schema['types'] as $type) { + if (!empty($type['extended_by'])) { + $this->abstractClasses[] = $type['name']; + foreach ($type['extended_by'] as $extendedType) { + $this->extendedClasses[$extendedType] = $type['name']; + } + } + } + print_r($this->extendedClasses); + print_r($this->abstractClasses); $this->namespace = $namespace; } @@ -125,7 +143,7 @@ class StubCreator ): array { $interfaceFile = new PhpFile; $interfaceNamespace = $interfaceFile->addNamespace($namespace); - $interface = $interfaceNamespace->addInterface('TypeInterface'); + $interfaceNamespace->addInterface('TypeInterface'); $responseFile = new PhpFile; $responseNamespace = $responseFile->addNamespace($namespace); $response = $responseNamespace->addClass('Response') @@ -167,7 +185,14 @@ class StubCreator $phpNamespace = $file->addNamespace($namespace); $typeClass = $phpNamespace->addClass($type['name']) ->setType('class'); - $typeClass->addImplement($namespace . '\\TypeInterface'); + if (in_array($type['name'], $this->abstractClasses)) { + $typeClass->setAbstract(); + } + if (array_key_exists($type['name'], $this->extendedClasses)) { + $typeClass->addExtend($namespace . '\\' . $this->extendedClasses[$type['name']]); + } else { + $typeClass->addImplement($namespace . '\\TypeInterface'); + } foreach ($type['fields'] as $field) { ['types' => $fieldTypes, 'comments' => $fieldComments] = $this->parseFieldTypes( $field['types'],