-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
82188d4
commit c4c086b
Showing
4 changed files
with
159 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace Haemanthus\CodeIgniter3IdeHelper\Casts; | ||
|
||
abstract class AbstractNodeCast | ||
{ | ||
/** | ||
* Undocumented variable | ||
* | ||
* @var array<string, array<string, string>> | ||
*/ | ||
protected $map = [ | ||
'cores' => [ | ||
'benchmark' => 'CI_Benchmark', | ||
'config' => 'CI_Config', | ||
'input' => 'CI_Input', | ||
'lang' => 'CI_Lang', | ||
'load' => 'CI_Loader', | ||
'output' => 'CI_Output', | ||
'security' => 'CI_Security', | ||
'uri' => 'CI_URI', | ||
], | ||
'libraries' => [ | ||
'cache' => 'CI_Cache', | ||
'calendar' => 'CI_Calendar', | ||
// 'driver' => 'CI_Driver', | ||
'email' => 'CI_Email', | ||
'encryption' => 'CI_Encryption', | ||
'form_validation' => 'CI_Form_validation', | ||
'ftp' => 'CI_Ftp', | ||
'image_lib' => 'CI_Image_lib', | ||
'migration' => 'CI_Migration', | ||
'pagination' => 'CI_Pagination', | ||
'parser' => 'CI_Parser', | ||
'profiler' => 'CI_Profiler', | ||
'session' => 'CI_Session', | ||
'table' => 'CI_Table', | ||
'trackback' => 'CI_Trackback', | ||
'typography' => 'CI_Typography', | ||
'unit_test' => 'CI_Unit_test', | ||
'upload' => 'CI_Upload', | ||
'user_agent' => 'CI_User_agent', | ||
'xmlrpc' => 'CI_Xmlrpc', | ||
'xmlrpcs' => 'CI_Xmlrpcs', | ||
'zip' => 'CI_Zip', | ||
], | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Haemanthus\CodeIgniter3IdeHelper\Casts; | ||
|
||
use Haemanthus\CodeIgniter3IdeHelper\Objects\DocumentBlockDTO; | ||
use PhpParser\Node\Arg; | ||
use PhpParser\Node\Expr\ConstFetch; | ||
use PhpParser\Node\Expr\MethodCall; | ||
use PhpParser\Node\Scalar\String_; | ||
|
||
class NodeLibraryCast extends AbstractNodeCast | ||
{ | ||
protected const KEY = 'libraries'; | ||
|
||
protected function classType(string $name): string | ||
{ | ||
if (array_key_exists($name, $this->map[self::KEY]) === true) { | ||
return $this->map[self::KEY][$name]; | ||
} | ||
|
||
return $name; | ||
} | ||
|
||
/** | ||
* Undocumented function | ||
* | ||
* @param array<Arg> $args | ||
* @return bool | ||
*/ | ||
protected function isArgsTypeScalarString(array $args): bool | ||
{ | ||
return array_reduce($args, fn (bool $carry, Arg $arg): bool => ( | ||
$arg->name === null | ||
&& ($arg->value instanceof String_ || $arg->value instanceof ConstFetch) | ||
&& $carry | ||
), true); | ||
} | ||
|
||
/** | ||
* Undocumented function | ||
* | ||
* @param array<Arg> $args | ||
* @return DocumentBlockDTO | ||
*/ | ||
protected function castScalarStringArg(array $args): DocumentBlockDTO | ||
{ | ||
$name = array_key_exists(2, $args) ? $args[2]->value->value : $args[0]->value->value; | ||
$type = $this->classType($args[0]->value->value); | ||
|
||
return new DocumentBlockDTO( | ||
$name, | ||
$type, | ||
); | ||
} | ||
|
||
public function cast(MethodCall $node): ?DocumentBlockDTO | ||
{ | ||
switch (true) { | ||
case $this->isArgsTypeScalarString($node->args): | ||
$block = $this->castScalarStringArg($node->args); | ||
break; | ||
|
||
default: | ||
$block = null; | ||
break; | ||
} | ||
|
||
return $block; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace Haemanthus\CodeIgniter3IdeHelper\Objects; | ||
|
||
class DocumentBlockDTO | ||
{ | ||
protected string $name; | ||
|
||
protected ?string $type; | ||
|
||
public function __construct( | ||
string $name, | ||
?string $type = null | ||
) { | ||
$this->name = $name; | ||
$this->type = $type; | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return $this->name; | ||
} | ||
|
||
public function getType(): ?string | ||
{ | ||
return $this->type; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters