Skip to content

Commit

Permalink
Merge branch 'release/1.1.3'
Browse files Browse the repository at this point in the history
  • Loading branch information
DannyvdSluijs committed Jan 31, 2020
2 parents 3f50be4 + 363c6f9 commit b14b7ac
Show file tree
Hide file tree
Showing 23 changed files with 55,970 additions and 898 deletions.
5 changes: 5 additions & 0 deletions .dependabot/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
version: 1
update_configs:
- package_manager: "php:composer"
directory: ""
update_schedule: "live"
7 changes: 7 additions & 0 deletions .mergify.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pull_request_rules:
- name: automatic merge for Dependabot pull requests
conditions:
- author=dependabot-preview[bot]
actions:
merge:
method: squash
22 changes: 22 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
language: php
php:
- 7.2
- 7.3
- 7.4
- nightly

matrix:
allow_failures:
- php: nightly

install:
- curl -s http://getcomposer.org/installer | php
- php composer.phar install --dev --no-interaction
script:
- mkdir -p build/logs;
- composer phpunit
after_success:
- travis_retry php vendor/bin/php-coveralls -v
notifications:
email:
- [email protected]
15 changes: 15 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,21 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.1.3] - 2020-01-31
### Added
- Meta file builder command was added
- Add url to Exact App Center during cli authorisation setup
- Support for Travis, Dependabot and Mergify has been added
- Add unit testing
- Added badges to Readme
### Changed
- phpunit/phpunit update from 8.5.1 to 8.5.2
- rector/rector update from 0.5.23 to 0.6.14
- symfony/http-foundation from 4.4.2 to 4.4.3
- symfony/console from 4.4.2 to 4.4.3
- symfony/filesystem 4.4.2 to 4.4.3
- squizlabs/php_codesniffer 3.5.3 to 3.5.4

## [1.1.2] - 2019-10-30
### Added
- Add static method to fetch the endpoint URI
Expand Down
23 changes: 18 additions & 5 deletions DevTools/Command/AuthorisationSetupCommand.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace DevTools\Command;

Expand Down Expand Up @@ -45,7 +47,13 @@ protected function configure(): void
HELP
)
->setDefinition([
new InputOption('output', 'o', InputOption::VALUE_REQUIRED, 'The output directory for the tokens', getcwd()),
new InputOption(
'output',
'o',
InputOption::VALUE_REQUIRED,
'The output directory for tokens',
getcwd()
),
]);
}

Expand Down Expand Up @@ -83,13 +91,13 @@ private function askClientDetails(): OAuthClient
$clientId = $this->questionHelper->ask(
$this->input,
$this->output,
new Question('What is the Client ID (Can be found in the Exact App Center)? ')
new Question('What is the Client ID (Can be found in the Exact App Center https://apps.exactonline.com)? ')
);

$clientSecret = $this->questionHelper->ask(
$this->input,
$this->output,
new Question('What is the Client secret (Can be found in the Exact App Center)? ')
new Question('What is the Client secret (Can also be found in the Exact App Center)? ')
);

return new OAuthClient($clientId, $clientSecret);
Expand Down Expand Up @@ -134,6 +142,10 @@ private function getAuthorisationCode(OAuthClient $client): string
$this->stopHttpListening();
unlink($filename);

if ($code === null) {
throw new \RuntimeException('Unable to retrieve the authorisation code');
}

return $code;
}

Expand Down Expand Up @@ -193,7 +205,8 @@ private function writeToFile(OAuthClient $client, OAuthTokenSet $tokenSet): void
$path = $this->getFullDestinationPath($output);
$fileName = $path . DIRECTORY_SEPARATOR . 'oauth.json';

file_put_contents($fileName, json_encode(array_merge($client->jsonSerialize(), $tokenSet->jsonSerialize()), JSON_PRETTY_PRINT));
$data = array_merge($client->jsonSerialize(), $tokenSet->jsonSerialize());
file_put_contents($fileName, json_encode($data, JSON_PRETTY_PRINT));

$this->output->writeln('Access and refresh tokens are available in: ' . $fileName);
}
Expand Down
67 changes: 62 additions & 5 deletions DevTools/Command/EntityBuilderCommand.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace DevTools\Command;

use DevTools\TwigExtension;
use DevTools\Writers\EntityWriter;
use MetaDataTool\DocumentationCrawler;
use MetaDataTool\Command\MetaDataBuilderCommand;
use MetaDataTool\ValueObjects\Endpoint;
use MetaDataTool\ValueObjects\EndpointCollection;
use MetaDataTool\ValueObjects\HttpMethodMask;
use MetaDataTool\ValueObjects\Property;
use MetaDataTool\ValueObjects\PropertyCollection;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\NullOutput;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Twig\Environment;
Expand All @@ -28,18 +37,27 @@ protected function configure(): void
)
->setDefinition([
new InputOption('destination', 'd', InputOption::VALUE_REQUIRED, 'The destination directory', getcwd()),
new InputOption('refresh-meta-data', 'm', InputOption::VALUE_NONE, 'Refresh the meta data'),
]);
}

protected function execute(InputInterface $input, OutputInterface $output): int
{
/* Meta data */
$endpoints = (new DocumentationCrawler())->run();
if (! is_readable('./meta-data.json') || $input->getOption('refresh-meta-data')) {
$this->refreshMetaData();
}

/* Load meta data from file */
$endpoints = $this->loadEndpoints();

$twig = new Environment(new FilesystemLoader('./template/'));
$twig->addExtension(new TwigExtension());

/** @var string $destination */
$destination = $input->getOption('destination');

$writer = new EntityWriter(
$this->getFullDestinationPath($input->getOption('destination')),
$this->getFullDestinationPath($destination),
new Filesystem(),
$twig
);
Expand All @@ -58,4 +76,43 @@ private function getFullDestinationPath(string $destination): string
return getcwd() . DIRECTORY_SEPARATOR . $destination;
}

private function refreshMetaData(): void
{
$command = new MetaDataBuilderCommand();
$command->run(new ArrayInput(['--destination' => '.']), new NullOutput());
}

private function loadEndpoints(): EndpointCollection
{
$contents = file_get_contents('meta-data.json');
if ($contents === false) {
throw new \RuntimeException('Unable to read from meta-data.json');
}
$object = json_decode($contents, false);
$endpointCollection = new EndpointCollection();

foreach ($object as $endpoint) {
$properties = [];
foreach ($endpoint->properties as $property) {
$properties[] = new Property(
$property->name,
$property->type,
$property->description,
$property->primaryKey,
HttpMethodMask::none() /* @todo */
);
}
$endpointCollection->add(new Endpoint(
$endpoint->endpoint,
$endpoint->documentation,
$endpoint->scope,
$endpoint->uri,
HttpMethodMask::none(), /* @todo */
$endpoint->example,
new PropertyCollection(...$properties)
));
}

return $endpointCollection;
}
}
10 changes: 10 additions & 0 deletions DevTools/Exceptions/ExceptionInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

namespace DevTools\Exceptions;

interface ExceptionInterface
{

}
13 changes: 13 additions & 0 deletions DevTools/Exceptions/SerializationException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace DevTools\Exceptions;

class SerializationException extends \Exception implements ExceptionInterface
{
public static function jsonEncodingFailed(): self
{
return new static('Something went wrong when encoding to json');
}
}
4 changes: 3 additions & 1 deletion DevTools/MetaDataHelper.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace DevTools;

Expand Down
26 changes: 19 additions & 7 deletions DevTools/TwigExtension.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace DevTools;

Expand All @@ -12,19 +14,19 @@ class TwigExtension extends AbstractExtension
public function getFilters(): array
{
return [
new TwigFilter('namespace', function (Endpoint $endpoint) : string {
new TwigFilter('namespace', function (Endpoint $endpoint): string {
return $this->namespace($endpoint);
}),
new TwigFilter('className', function (Endpoint $endpoint) : string {
new TwigFilter('className', function (Endpoint $endpoint): string {
return $this->className($endpoint);
}),
new TwigFilter('derivePropertyType', function (Property $property) : string {
new TwigFilter('derivePropertyType', function (Property $property): string {
return $this->derivePropertyType($property);
}),
new TwigFilter('derivePropertyName', function (Property $property) : string {
new TwigFilter('derivePropertyName', function (Property $property): string {
return $this->derivePropertyName($property);
}),
new TwigFilter('deriveEndpointUri', function (Endpoint $endpoint) : string {
new TwigFilter('deriveEndpointUri', function (Endpoint $endpoint): string {
return $this->deriveEndpointUri($endpoint);
}),
];
Expand All @@ -34,14 +36,24 @@ public function namespace(Endpoint $endpoint): string
{
$uri = str_replace(['/api/v1/{division}', '/api/v1/current', '/'], ['', '', '\\'], $endpoint->getUri());
$pos = strrpos($uri, '\\');

if ($pos === false) {
throw new \RuntimeException('Failed to find the position of the namespace seperator');
}

return 'ExactOnline\ApiClient\Entity' . ucwords(substr($uri, 0, $pos), '\\');
}

public function className(Endpoint $endpoint): string
{
$elements = explode('/', $endpoint->getUri());
$taintedClassName = array_pop($elements);

if ($taintedClassName === null) {
throw new \RuntimeException('Unable to derive class name from endpoint uri');
}

return ucfirst(array_pop($elements));
return ucfirst($taintedClassName);
}

public function derivePropertyType(Property $property): string
Expand Down
7 changes: 4 additions & 3 deletions DevTools/ValueObjects/OAuthClient.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php declare(strict_types=1);
<?php

namespace DevTools\ValueObjects;
declare(strict_types=1);

namespace DevTools\ValueObjects;

class OAuthClient implements \JsonSerializable
{
Expand Down Expand Up @@ -33,4 +34,4 @@ public function jsonSerialize(): array
'client_secret' => $this->secret
];
}
}
}
7 changes: 4 additions & 3 deletions DevTools/ValueObjects/OAuthTokenSet.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
<?php declare(strict_types=1);
<?php

namespace DevTools\ValueObjects;
declare(strict_types=1);

namespace DevTools\ValueObjects;

class OAuthTokenSet implements \JsonSerializable
{
Expand Down Expand Up @@ -42,4 +43,4 @@ public function jsonSerialize()
'expires_at' => $this->accessTokenValidUntil->format(\DATE_ATOM)
];
}
}
}
11 changes: 4 additions & 7 deletions DevTools/Writers/EntityWriter.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace DevTools\Writers;

Expand Down Expand Up @@ -45,11 +47,6 @@ public function write(EndpointCollection $endpointCollection): void

private function buildContent(Endpoint $endpoint): string
{
return $this->templateEngine->render(
'entity.php.template',
[
'endpoint' => $endpoint
]
);
return $this->templateEngine->render('entity.php.template', ['endpoint' => $endpoint]);
}
}
Loading

0 comments on commit b14b7ac

Please sign in to comment.