Skip to content

Commit

Permalink
Merge pull request #1 from AlvaroRosado/master
Browse files Browse the repository at this point in the history
Some refactors in classes model
  • Loading branch information
cluster28 authored Mar 11, 2022
2 parents 7887be7 + 4c7a1fe commit f1b08d7
Show file tree
Hide file tree
Showing 16 changed files with 347 additions and 537 deletions.
35 changes: 33 additions & 2 deletions src/Annotation/ShareAnnotation.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,44 @@
class ShareAnnotation
{
public string $date;

public string $description;

public array $tags = [];

public function getDateTime()
{
return DateTime::createFromFormat('Y-m-d', $this->date);
}

public function getDate(): string
{
return $this->date;
}

public function setDate(string $date): self
{
$this->date = $date;
return $this;
}

public function getDescription(): string
{
return $this->description;
}

public function setDescription(string $description): self
{
$this->description = $description;
return $this;
}

public function getTags(): array
{
return $this->tags;
}

public function setTags(array $tags): self
{
$this->tags = $tags;
return $this;
}
}
29 changes: 27 additions & 2 deletions src/Extractor/AnnotationExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Cluster28\TeamShareDocumentation\Extractor;

use Cluster28\TeamShareDocumentation\Annotation\ShareAnnotation;
use Cluster28\TeamShareDocumentation\Model\AnnotationData;
use Doctrine\Common\Annotations\AnnotationReader;
use ReflectionClass;
use ReflectionMethod;
Expand All @@ -26,7 +27,12 @@ public function extractClassAnnotations(ReflectionClass $reflectionClass): array
if (count($classAnnotations) > 0) {
foreach ($classAnnotations as $classAnnotation) {
if ($classAnnotation instanceof ShareAnnotation) {
$allClassAnnotations[] = [$reflectionClass, $classAnnotation];
$allClassAnnotations[] = $this->createAnnotationData(
$classAnnotation,
$reflectionClass->getName(),
false,
$reflectionClass->getName()
);
}
}
}
Expand All @@ -43,12 +49,31 @@ public function extractMethodsAnnotations(ReflectionClass $reflectionClass): arr
if (count($methodAnnotations) > 0) {
foreach ($methodAnnotations as $methodAnnotation) {
if ($methodAnnotation instanceof ShareAnnotation) {
$allMethodAnnotations[] = [$reflectionMethod, $methodAnnotation];
$allMethodAnnotations[] = $this->createAnnotationData(
$methodAnnotation,
$reflectionClass->getName(),
true,
$reflectionMethod->getName()
);
}
}
}
}

return $allMethodAnnotations;
}

public function createAnnotationData(
ShareAnnotation $shareAnnotation,
string $className,
bool $inMethod = false,
string $methodName = ''
) {
$annotation = new AnnotationData();
$annotation->setClassName($className);
$annotation->setIsInMethod($inMethod);
$annotation->setMethodName($methodName);
$annotation->setAnnotation($shareAnnotation);
return $annotation;
}
}
29 changes: 9 additions & 20 deletions src/Extractor/Extractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

namespace Cluster28\TeamShareDocumentation\Extractor;

use Cluster28\TeamShareDocumentation\Annotation\ShareAnnotation;
use Cluster28\TeamShareDocumentation\Configuration\Configuration;
use Cluster28\TeamShareDocumentation\Model\Collection\Annotations;
use Cluster28\TeamShareDocumentation\Model\ExtractionResult;
use Cluster28\TeamShareDocumentation\Model\ClassInfo;
use Cluster28\TeamShareDocumentation\Model\ResultInfo;
use Cluster28\TeamShareDocumentation\Parser\ParserInterface;
use Reflector;

/**
* @author Jordi Rejas <[email protected]>
Expand All @@ -22,30 +22,19 @@ public function __construct(
ParserInterface $parser,
AnnotationExtractorInterface $annotationExtractor
) {
$this->configuration = $configuration;
$this->parser = $parser;
$this->annotationExtractor = $annotationExtractor;
}

public function extractAnnotations(): Annotations
public function execute(): ExtractionResult
{
$classes = $this->parser->parseFiles();
$annotations = new Annotations();
$extractionResult = new ExtractionResult();

foreach ($classes->toArray() as $class) {
foreach (
array_merge(
$this->annotationExtractor->extractClassAnnotations($class),
$this->annotationExtractor->extractMethodsAnnotations($class)
) as $array) {
/** @var Reflector $reflector */
$reflector = $array[0];
/** @var ShareAnnotation $shareAnnotation */
$shareAnnotation = $array[1];
$annotations->addAnnotation($reflector, $shareAnnotation);
}
foreach ($this->parser->parseFiles() as $reflectionClass) {
$extractionResult->addClassAnnotations($this->annotationExtractor->extractClassAnnotations($reflectionClass));
$extractionResult->addMethodAnnotations($this->annotationExtractor->extractMethodsAnnotations($reflectionClass));
}

return $annotations;
return $extractionResult;
}
}
4 changes: 2 additions & 2 deletions src/Extractor/ExtractorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

namespace Cluster28\TeamShareDocumentation\Extractor;

use Cluster28\TeamShareDocumentation\Model\Collection\Annotations;
use Cluster28\TeamShareDocumentation\Model\ExtractionResult;

/**
* @author Jordi Rejas <[email protected]>
*/
interface ExtractorInterface
{
public function extractAnnotations(): Annotations;
public function execute(): ExtractionResult;
}
69 changes: 69 additions & 0 deletions src/Model/AnnotationData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

namespace Cluster28\TeamShareDocumentation\Model;

use Cluster28\TeamShareDocumentation\Annotation\ShareAnnotation;

class AnnotationData
{
private ShareAnnotation $annotation;
private bool $isInClass = false;
private bool $isInMethod = false;
private string $className = '';
private string $methodName = '';

public function getAnnotation(): ShareAnnotation
{
return $this->annotation;
}

public function setAnnotation(ShareAnnotation $annotation): self
{
$this->annotation = $annotation;
return $this;
}

public function isInClass(): bool
{
return $this->isInClass;
}

public function setIsInClass(bool $isInClass): self
{
$this->isInClass = $isInClass;
return $this;
}

public function isInMethod(): bool
{
return $this->isInMethod;
}

public function setIsInMethod(bool $isInMethod): self
{
$this->isInMethod = $isInMethod;
return $this;
}

public function getClassName(): string
{
return $this->className;
}

public function setClassName(string $className): self
{
$this->className = $className;
return $this;
}

public function getMethodName(): string
{
return $this->methodName;
}

public function setMethodName(string $methodName): self
{
$this->methodName = $methodName;
return $this;
}
}
Loading

0 comments on commit f1b08d7

Please sign in to comment.