Skip to content

Commit

Permalink
#171. Add Documentation abstract class + interface + refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurkushman committed Jun 9, 2019
1 parent ef6ea7b commit 323b625
Show file tree
Hide file tree
Showing 5 changed files with 114 additions and 28 deletions.
7 changes: 4 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@
}
},
"require-dev": {
"codeception/codeception": "^2.4",
"darkaonline/l5-swagger": "5.8.*",
"fzaninotto/faker": "^1.7",
"laravel/framework": ">=5.3",
"phpunit/phpunit": ">=6.5",
"mockery/mockery": "~1.0",
"codeception/codeception": "^2.4",
"fzaninotto/faker": "^1.7"
"phpunit/phpunit": ">=6.5"
},
"minimum-stability": "dev",
"prefer-stable": true,
Expand Down
34 changes: 31 additions & 3 deletions src/Blocks/ContentManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use SoliDry\Controllers\BaseCommand;
use SoliDry\Helpers\Console;
use SoliDry\Helpers\Json;
use SoliDry\Helpers\MethodOptions;
use SoliDry\Types\DefaultInterface;
use SoliDry\Types\PhpInterface;
Expand Down Expand Up @@ -212,6 +211,35 @@ protected function setComment(string $comment, int $tabs = 1): void
. PhpInterface::SPACE . $comment . PHP_EOL;
}

/**
* @param int $tabs
*/
protected function openComment(int $tabs = 1): void
{
$this->sourceCode .= $this->setTabs($tabs) . PhpInterface::SLASH
. PhpInterface::ASTERISK . PhpInterface::ASTERISK . PHP_EOL;
}

/**
* @param int $tabs
*/
protected function closeComment(int $tabs = 1): void
{
$this->sourceCode .= $this->setTabs($tabs) . PhpInterface::ASTERISK
. PhpInterface::SLASH . PHP_EOL;
}

/**
* @param string $comment
* @param int $tabs
* @param int $afterTabs
*/
protected function setStarredComment(string $comment, int $tabs = 1, int $afterTabs = 0): void
{
$this->sourceCode .= $this->setTabs($tabs) . PhpInterface::ASTERISK
. PhpInterface::SPACE . $this->setTabs($afterTabs) . $comment . PHP_EOL;
}

/**
* Sets an amount of tabs to source code
* @param int $amount
Expand Down Expand Up @@ -419,7 +447,7 @@ public function quoteParam(string $param): string
*
* @param string $entityFile
*/
private function setBeforeProps(string $entityFile): void
protected function setBeforeProps(string $entityFile): void
{
$this->resourceCode = file_get_contents($entityFile);
$end = mb_strpos($this->resourceCode, DefaultInterface::PROPS_START, NULL, PhpInterface::ENCODING_UTF8) - 3;
Expand All @@ -431,7 +459,7 @@ private function setBeforeProps(string $entityFile): void
*
* @param string $till
*/
private function setAfterProps($till = NULL): void
protected function setAfterProps($till = NULL): void
{
$start = $this->setTabs() . mb_strpos($this->resourceCode, DefaultInterface::PROPS_END, NULL,
PhpInterface::ENCODING_UTF8) - 3;
Expand Down
28 changes: 6 additions & 22 deletions src/Blocks/Controllers.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use SoliDry\Extension\BaseController;
use SoliDry\Helpers\Classes;
use SoliDry\Helpers\Console;
use SoliDry\ApiGenerator;
use SoliDry\Types\ControllersInterface;
use SoliDry\Types\DefaultInterface;
use SoliDry\Types\PhpInterface;
Expand All @@ -14,26 +13,8 @@
* Class Controllers
* @package SoliDry\Blocks
*/
class Controllers implements ControllersInterface
class Controllers extends Documentation implements ControllersInterface
{
use ContentManager;

/** @var ApiGenerator generator */
private $generator;
private $sourceCode = '';
private $className;

/**
* Controllers constructor.
*
* @param ApiGenerator $generator
*/
public function __construct($generator)
{
$this->generator = $generator;
$this->className = Classes::getClassName($this->generator->objectName);
}

/**
* Creates the DefaultController and outputs path to the console
*/
Expand All @@ -45,14 +26,15 @@ public function createDefault(): void
. $this->generator->defaultController
. DefaultInterface::CONTROLLER_POSTFIX
. PhpInterface::PHP_EXT;

$isCreated = FileManager::createFile($fileController, $this->sourceCode);
if($isCreated)
{
Console::out($fileController . PhpInterface::SPACE . Console::CREATED, Console::COLOR_GREEN);
}
}

private function resetContent()
protected function resetContent()
{
$this->setBeforeProps($this->getEntityFile($this->generator->formatControllersPath(), DefaultInterface::CONTROLLER_POSTFIX));
$this->setComment(DefaultInterface::PROPS_START, 0);
Expand All @@ -62,7 +44,7 @@ private function resetContent()
/**
* Sets *Controller content
*/
private function setContent()
protected function setContent()
{
$this->setTag();
$this->setNamespace(
Expand Down Expand Up @@ -99,6 +81,8 @@ private function setDefaultContent()
$this->setComment(DefaultInterface::PROPS_START);
$this->setComment(DefaultInterface::PROPS_END);

$this->setDefaultDocs();

$this->endClass();
}
}
44 changes: 44 additions & 0 deletions src/Blocks/Documentation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

namespace SoliDry\Blocks;

use SoliDry\ApiGenerator;
use SoliDry\Controllers\BaseCommand;
use SoliDry\Helpers\Classes;
use SoliDry\Types\DefaultInterface;

/**
* Class Documentation
*
* @package SoliDry\Blocks
*
* @property BaseCommand generator
*/
abstract class Documentation
{
use ContentManager;

protected $generator;
protected $sourceCode = '';
protected $className;

/**
* Controllers constructor.
*
* @param ApiGenerator $generator
*/
public function __construct($generator)
{
$this->generator = $generator;
$this->className = Classes::getClassName($this->generator->objectName);
}

protected function setDefaultDocs()
{
$this->setComment(DefaultInterface::METHOD_START);



$this->setComment(DefaultInterface::METHOD_END);
}
}
29 changes: 29 additions & 0 deletions src/Types/DocumentationInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace SoliDry\Types;


interface DocumentationInterface
{

public const OA_INFO = '@OA\Info';
public const OA_GET = '@OA\Get';
public const OA_POST = '@OA\Post';
public const OA_PATCH = '@OA\Patch';
public const OA_DELETE = '@OA\Delete';


public const OA_PARAMETER = '@OA\Parameter';
public const OA_SCHEMA = '@OA\Schema';
public const OA_REQUEST_BODY = '@OA\RequestBody';
public const OA_RESPONSE = '@OA\Response';

public const PATH = 'path';
public const SUMMARY = 'summary';
public const TAGS = 'tags';
public const DESCRIPTION = 'description';
public const RESPONSE = 'response';
public const IN = 'in';
public const NAME = 'name';
public const REQUIRED = 'required';
}

0 comments on commit 323b625

Please sign in to comment.