Skip to content

Commit

Permalink
Initial version??
Browse files Browse the repository at this point in the history
  • Loading branch information
JordanRL committed Jul 5, 2021
1 parent a010553 commit 1b2afc8
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 34 deletions.
14 changes: 12 additions & 2 deletions src/Samsara/Roster/Processors/Base/BaseCodeProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
namespace Samsara\Roster\Processors\Base;


use Samsara\Mason\Tags\Base\DocBlockTag;
use Samsara\Mason\DocBlockProcessor;
use Samsara\Roster\Processors\TemplateProcessor;
use Samsara\Roster\TemplateFactory;

abstract class BaseCodeProcessor
{
protected string $declaringClass = '';
protected DocBlockProcessor $docBlock;
protected TemplateProcessor $templateProcessor;

public function getDeclaringClass(): string
{
Expand Down Expand Up @@ -52,7 +55,14 @@ protected function fixOutput($option1, $option2, $option3)
return (empty($option1) ? (empty($option2) ? $option3 : $option2) : $option1);
}

abstract protected function templateLoader(string $templateName);
protected function templateLoader(string $templateName)
{
if (isset($this->docBlock) && array_key_exists('roster-template', $this->docBlock->others)) {
$this->templateProcessor = TemplateFactory::getTemplate($this->docBlock->others['roster-template']->description);
} else {
$this->templateProcessor = TemplateFactory::getTemplate($templateName);
}
}

abstract public function compile();

Expand Down
12 changes: 0 additions & 12 deletions src/Samsara/Roster/Processors/ClassProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class ClassProcessor extends BaseCodeProcessor
/** @var TraitInlineProcessor[] */
private array $traits = [];
private array $interfaces = [];
private DocBlockProcessor $docBlock;
private TemplateProcessor $templateProcessor;


/**
Expand All @@ -48,21 +46,11 @@ public function __construct(ReflectionClass $class, string $templateName = 'clas

$this->templateLoader($templateName);

$this->shortName = $class->getShortName();
$this->declaringClass = $class->getName();

$this->buildClassInfo();
}

protected function templateLoader(string $templateName)
{
if (array_key_exists('roster-template', $this->docBlock->others)) {
$this->templateProcessor = TemplateFactory::getTemplate($this->docBlock->others['roster-template']->description);
} else {
$this->templateProcessor = TemplateFactory::getTemplate($templateName);
}
}

protected function buildClassInfo()
{

Expand Down
9 changes: 3 additions & 6 deletions src/Samsara/Roster/Processors/InterfaceInlineProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,17 @@
use Samsara\Mason\DocBlockProcessor;
use ReflectionClass;
use Samsara\Roster\TemplateFactory;
use Samsara\Roster\Processors\Base\BaseCodeProcessor;

class InterfaceInlineProcessor extends Base\BaseCodeProcessor
class InterfaceInlineProcessor extends BaseCodeProcessor
{
private ReflectionClass $interface;
private TemplateProcessor $templateProcessor;
private DocBlockProcessor $docBlock;

public function __construct(ReflectionClass $interface)
{
$this->interface = $interface;
$this->templateProcessor = TemplateFactory::getTemplate('classInterface');
$this->templateLoader('classInterface');
$this->docBlock = new DocBlockProcessor($interface->getDocComment(), false);

$this->shortName = $interface->getShortName();
}

public function compile(): string
Expand Down
9 changes: 2 additions & 7 deletions src/Samsara/Roster/Processors/MethodProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,14 @@ class MethodProcessor extends BaseCodeProcessor
{

private \ReflectionMethod $method;
private TemplateProcessor $templateProcessor;

private MethodArgumentProcessor $argumentProcessor;
private MethodArgumentDetailProcessor $argumentDetailProcessor;

private DocBlockProcessor $docBlock;

public function __construct(\ReflectionMethod $method, string $templateName)
public function __construct(\ReflectionMethod $method, string $templateName = 'method')
{
$this->method = $method;
$this->templateProcessor = TemplateFactory::getTemplate($templateName);
$this->templateLoader($templateName);

$this->shortName = $method->getShortName();
$this->declaringClass = $method->getDeclaringClass()->getName();

$this->buildMethodInfo();
Expand Down
5 changes: 1 addition & 4 deletions src/Samsara/Roster/Processors/PropertyProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,15 @@ class PropertyProcessor extends BaseCodeProcessor
{

private ReflectionProperty $property;
private DocBlockProcessor $docBlock;
private TemplateProcessor $templateProcessor;

public function __construct(ReflectionProperty $property, string $templateName)
{
$this->property = $property;
$this->docBlock = new DocBlockProcessor($property->getDocComment(), false);

$this->templateProcessor = TemplateFactory::getTemplate($templateName);
$this->templateLoader($templateName);

$this->declaringClass = $property->getDeclaringClass()->getName();
$this->shortName = $property->getName();
}

public function compile(): string
Expand Down
4 changes: 1 addition & 3 deletions src/Samsara/Roster/Processors/TraitInlineProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@ class TraitInlineProcessor extends Base\BaseCodeProcessor

private ReflectionClass $trait;
private array $aliases;
private TemplateProcessor $templateProcessor;
private DocBlockProcessor $docBlock;

public function __construct(ReflectionClass $trait, array $aliases = [])
{
$this->trait = $trait;
$this->templateProcessor = TemplateFactory::getTemplate('classTrait');
$this->templateLoader('classTrait');
$this->docBlock = new DocBlockProcessor($trait->getDocComment(), false);
$this->aliases = $aliases;
}
Expand Down

0 comments on commit 1b2afc8

Please sign in to comment.