Skip to content

Commit

Permalink
Merge pull request #3 from makeey/feature-php-7.4
Browse files Browse the repository at this point in the history
Move application to the php 7.4. Fix a couple bugs with function
  • Loading branch information
makeey authored Jul 26, 2020
2 parents 7467664 + 8394595 commit 5cd94fb
Show file tree
Hide file tree
Showing 38 changed files with 246 additions and 184 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ version: 2
jobs:
build:
docker:
- image: php:7.2.17
- image: php:7.4
steps:
- run:
name: Install system packages
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
],
"license": "MIT",
"require": {
"php": "^7.2",
"php": "^7.4",
"php-di/php-di": "^6.0",
"php-ds/php-ds": "^1.2",
"symfony/console": "^5.0"
Expand Down
3 changes: 1 addition & 2 deletions src/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@

class Application implements IApplication
{
/** @var \Symfony\Component\Console\Application */
private $application;
private \Symfony\Component\Console\Application $application;

public function __construct(Command ...$commands)
{
Expand Down
6 changes: 2 additions & 4 deletions src/Command/GenerateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@

class GenerateCommand extends Command
{
/** @var Generator */
private $generator;
protected static $defaultName = 'generate';
private Generator $generator;

public function __construct(Generator $generator, string $name = null)
{
$this->generator = $generator;
parent::__construct($name);
}

protected static $defaultName = 'generate';

protected function configure(): void
{
$this->setDescription("Generate class diagram")
Expand Down
3 changes: 1 addition & 2 deletions src/FileWriter.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

class FileWriter implements IWriter
{
/** @var string|null */
private $path;
private ?string $path;

public function setOutput(string $path): IWriter
{
Expand Down
18 changes: 6 additions & 12 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,12 @@

class Generator
{
/** @var IWriter * */
private $writer;
/** @var IFileCollector * */
private $fileCollector;
/** @var IUMLDiagramFactory * */
private $umlFactory;
/** @var SourceParser * */
private $sourceParser;
/** @var IFormatter * */
private $formatter;
/** @var IFileTransform */
private $fileTransform;
private IWriter $writer;
private IFileCollector $fileCollector;
private IUMLDiagramFactory $umlFactory;
private SourceParser $sourceParser;
private IFormatter $formatter;
private IFileTransform $fileTransform;

public function __construct(
IWriter $writer,
Expand Down
15 changes: 6 additions & 9 deletions src/Parser/Entity/PhpClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,15 @@

final class PhpClass
{
/** @var string */
private $namespace;
/** @var string */
private $name;
private string $namespace;
private string $name;
/** @var PhpClassMember[] */
private $properties;
private array $properties;
/** @var PhpMethod[] */
private $methods;
/** @var string|null */
private $parent;
private array $methods;
private ?string $parent;
/** @var string[] */
private $implements;
private array $implements;

public function __construct(
string $name,
Expand Down
9 changes: 3 additions & 6 deletions src/Parser/Entity/PhpClassMember.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,9 @@

final class PhpClassMember
{
/** @var string|null */
private $type;
/** @var string */
private $name;
/** @var string */
private $accessModifier;
private ?string $type;
private string $name;
private string $accessModifier;

public function __construct(string $name, string $accessModifier, ?string $type)
{
Expand Down
10 changes: 4 additions & 6 deletions src/Parser/Entity/PhpFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

class PhpFile
{
/** @var string */
private $namespace;
private ?string $namespace = null;
/** @var PhpClass[] */
private $classes = [];
private array $classes = [];
/** @var PhpInterface[] */
private $interfaces = [];
/** @var array */
private $usedClasses = [];
private array $interfaces = [];
private array $usedClasses = [];

public function appendClasses(PhpClass ...$classes): self
{
Expand Down
11 changes: 4 additions & 7 deletions src/Parser/Entity/PhpInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

final class PhpInterface
{
/** @var string **/
private $namespace;
/** @var string */
private $interfaceName;
private string $namespace;
private string $interfaceName;
/** @var PhpMethod[] */
private $methods;
/** @var string|null */
private $parent;
private array $methods;
private ?string $parent;

public function __construct(string $interfaceName, array $methods, string $namespace, ?string $parent)
{
Expand Down
9 changes: 4 additions & 5 deletions src/Parser/Entity/PhpMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@

final class PhpMethod
{
/** @var string */
private $name;
private string $name;
/** @var PhpMethodParameter[] */
private $parameters;
/** @var string */
private $accessModifier;
private array $parameters;
private string $accessModifier;

public function __construct(string $name, array $parameters, string $accessModifier)
{
Expand All @@ -22,6 +20,7 @@ public function accessModifier(): string
{
return $this->accessModifier;
}

public function name(): string
{
return $this->name;
Expand Down
7 changes: 3 additions & 4 deletions src/Parser/Entity/PhpMethodParameter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
final class PhpMethodParameter
{
private const DEFAULT_TYPE = 'mixed';
/** @var string */
private $name;
/** @var string */
private $type;
private string $name;
private string $type;

public function __construct(string $name, ?string $type)
{
Expand All @@ -20,6 +18,7 @@ public function name(): string
{
return $this->name;
}

public function type(): string
{
return $this->type;
Expand Down
43 changes: 22 additions & 21 deletions src/Parser/SourceParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,17 @@

class SourceParser
{
/** @var PhpFile */
private $file;
private PhpFile $file;
/** @var Stack<PhpClass> */
private $classes;
private Stack $classes;
/** @var Stack<PhpMethod> */
private $methods;
private Stack $methods;
/** @var Stack<string> */
private $functions;
private Stack $functions;
/** @var Stack<PhpInterface> */
private $interfaces;
private Stack $interfaces;
/** @var Stack<int> */
private $controlStructure;
private Stack $controlStructure;

public function __construct()
{
Expand All @@ -53,7 +52,9 @@ public function __invoke(string $phpSourceCode): PhpFile
foreach ($tokens as $id => $token) {
switch ($token[0]) {
case T_NAMESPACE:
$this->processNamespace($id, $tokens);
if (strpos($token[1], "$") === false && $this->classes->isEmpty() && $this->interfaces->isEmpty()) {
$this->processNamespace($id, $tokens);
}
break;
case T_USE:
$this->processUseToken($id, $tokens);
Expand Down Expand Up @@ -93,6 +94,19 @@ private function processNamespace(int $id, array $tokens): void
$this->file->setNameSpace($namespaceToken->name());
}

private function processUseToken(int $id, array $tokens): void
{
if ($this->classes->isEmpty() === true) {
$useToken = new UseToken($id, $tokens);
$this->file->appendUsedClass(
[
'name' => $useToken->parts()->peek(),
'fullName' => $useToken->fullName()
]
);
}
}

private function processClassToken(int $id, array $tokens): void
{
if ($this->classes->isEmpty() === true) {
Expand Down Expand Up @@ -210,17 +224,4 @@ private function processCloseBrackets(): void
);
}
}

private function processUseToken(int $id, array $tokens): void
{
if ($this->classes->isEmpty() === true) {
$useToken = new UseToken($id, $tokens);
$this->file->appendUsedClass(
[
'name' => $useToken->parts()->peek(),
'fullName' => $useToken->fullName()
]
);
}
}
}
6 changes: 2 additions & 4 deletions src/Parser/Tokens/AbstractToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@

abstract class AbstractToken
{
/** @var int */
protected $id;
/** @var array */
protected $tokens;
protected int $id;
protected array $tokens;

public function __construct(int $id, array $tokens)
{
Expand Down
3 changes: 1 addition & 2 deletions src/Parser/Tokens/ClassMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

final class ClassMethod extends FunctionToken
{
/** @var string */
private $accessModifier;
private ?string $accessModifier = null;

public function accessModifier(): string
{
Expand Down
12 changes: 4 additions & 8 deletions src/Parser/Tokens/ClassToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@

final class ClassToken extends AbstractToken
{
/** @var string|null */
private $className;
/** @var string|null */
private $parent;
/** @var string[] */
private $interfaces;
/** @var bool */
private $isAnonymous = false;
private ?string $className = null;
private ?string $parent = null;
private ?array $interfaces = null;
private bool $isAnonymous = false;

public function className(): ?string
{
Expand Down
8 changes: 3 additions & 5 deletions src/Parser/Tokens/FunctionToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@ class FunctionToken extends AbstractToken
{
/** @var array */
private static $DEFAULT_VALUE_FOR_TYPES = ['null', 'true', 'false', '[', ']'];
/** @var array */
protected $params;
/** @var string */
protected $functionName;
protected ?array $params = null;
protected ?string $functionName = null;

public function functionName(): string
{
Expand All @@ -34,7 +32,7 @@ protected function parseName(): string
/**
* The situation when the function name intersect with php keywords (ex. namespace)
*/
return "Unresolved name";
return $next[1];
}

public function params(): array
Expand Down
17 changes: 7 additions & 10 deletions src/Parser/Tokens/InterfaceToken.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@

final class InterfaceToken extends AbstractToken
{
/** @var string */
private $interfaceName;
/** @var string|null */
private $parent;
private ?string $interfaceName = null;
private ?string $parent = null;

public function interfaceName(): string
{
Expand All @@ -18,12 +16,6 @@ public function interfaceName(): string
return $this->interfaceName;
}


public function getParent(): ?string
{
return $this->parent;
}

private function parseInterfaceName(): string
{
$next = $this->tokens[$this->id + 1];
Expand All @@ -33,4 +25,9 @@ private function parseInterfaceName(): string

return $next[1];
}

public function getParent(): ?string
{
return $this->parent;
}
}
Loading

0 comments on commit 5cd94fb

Please sign in to comment.