-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from yaegassy/feat/getter-setter-action
feat: getterSetter code action
- Loading branch information
Showing
13 changed files
with
1,220 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 |
---|---|---|
|
@@ -11,3 +11,5 @@ yarn-error.log | |
.github | ||
.eslintrc.js | ||
.prettierrc | ||
coverage | ||
_ref |
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
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
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 | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Dummy; | ||
|
||
use App\Dummy\Logger; | ||
|
||
class Sample1 | ||
{ | ||
private ?int $id; | ||
|
||
private string $name = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $description; | ||
|
||
private string|null $dummyCode = ''; | ||
|
||
private ?\DateTimeInterface $dummyDate = null; | ||
|
||
/** | ||
* @var ?string|\DateTimeInterface $multi1 | ||
* @var int $multi2 | ||
*/ | ||
private $dummyMulti1, $dummyMulti2; | ||
|
||
public function __construct( | ||
public int $prop1 = 0, | ||
public array $prop2 = [], | ||
) { | ||
} | ||
|
||
public function hello() | ||
{ | ||
} | ||
} | ||
|
||
class Sample2 | ||
{ | ||
private int $increment; | ||
|
||
public function example() | ||
{ | ||
} | ||
} |
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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Dummy\Logger; | ||
|
||
class Sample1 | ||
{ | ||
private ?int $id; | ||
|
||
private string $name = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $description; | ||
|
||
private string|null $dummyCode = ''; | ||
|
||
private ?\DateTimeInterface $dummyDate = null; | ||
|
||
/** | ||
* @var ?string|\DateTimeInterface $multi1 | ||
* @var int $multi2 | ||
*/ | ||
private $dummyMulti1, $dummyMulti2; | ||
|
||
public function __construct( | ||
public int $prop1 = 0, | ||
public array $prop2 = [], | ||
) { | ||
} | ||
|
||
public function hello() | ||
{ | ||
} | ||
} | ||
|
||
class Sample2 | ||
{ | ||
private int $increment; | ||
|
||
public function example() | ||
{ | ||
} | ||
} |
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,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Dummy; | ||
|
||
use App\Dummy\Logger; | ||
|
||
class Sample | ||
{ | ||
private ?int $id; | ||
|
||
private string $name = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $description; | ||
|
||
private string|null $dummyCode = ''; | ||
|
||
private ?\DateTimeInterface $dummyDate = null; | ||
|
||
/** | ||
* @var ?string|\DateTimeInterface $multi1 | ||
* @var int $multi2 | ||
*/ | ||
private $dummyMulti1, $dummyMulti2; | ||
|
||
public function __construct( | ||
public int $prop1 = 0, | ||
public array $prop2 = [], | ||
) { | ||
} | ||
|
||
public function hello() | ||
{ | ||
} | ||
} |
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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use App\Dummy\Logger; | ||
|
||
class Sample | ||
{ | ||
private ?int $id; | ||
|
||
private string $name = ''; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
private $description; | ||
|
||
private string|null $dummyCode = ''; | ||
|
||
private ?\DateTimeInterface $dummyDate = null; | ||
|
||
/** | ||
* @var ?string|\DateTimeInterface $multi1 | ||
* @var int $multi2 | ||
*/ | ||
private $dummyMulti1, $dummyMulti2; | ||
|
||
public function __construct( | ||
public int $prop1 = 0, | ||
public array $prop2 = [], | ||
) { | ||
} | ||
|
||
public function hello() | ||
{ | ||
} | ||
} |
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,77 @@ | ||
import { it, expect } from 'vitest'; | ||
import fs from 'fs'; | ||
import path from 'path'; | ||
|
||
import * as getterSetterParser from '../parsers/getterSetter'; | ||
|
||
const FIXTURES_DIR = path.join(__dirname, 'fixtures'); | ||
|
||
it('getMethod | Classes contain namespaces', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'standardNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getMethods(ast.children); | ||
expect(res.length).toBe(2); | ||
}); | ||
|
||
it('getMethod | Classes not contain namespaces', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'standardNonNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getMethods(ast.children); | ||
expect(res.length).toBe(2); | ||
}); | ||
|
||
it('getMethod | Multiple classes contain namespace', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'multipleNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getMethods(ast.children); | ||
expect(res.length).toBe(3); | ||
}); | ||
|
||
it('getMethod | Multiple classes not contain namespace', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'multipleNonNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getMethods(ast.children); | ||
expect(res.length).toBe(3); | ||
}); | ||
|
||
it('getClassesNodes | Classes contain namespaces', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'standardNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getClassesNodes(ast.children); | ||
expect(res.length).toBe(1); | ||
}); | ||
|
||
it('getClassesNodes | Classes not contain namespaces', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'standardNonNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getClassesNodes(ast.children); | ||
expect(res.length).toBe(1); | ||
}); | ||
|
||
it('getClassesNodes | Multiple classes contain namespace', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'multipleNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getClassesNodes(ast.children); | ||
expect(res.length).toBe(2); | ||
}); | ||
|
||
it('getClassesNodes | Multiple classes not contain namespace', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'multipleNonNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getClassesNodes(ast.children); | ||
expect(res.length).toBe(2); | ||
}); | ||
|
||
it('getPropertiesWithClassInfo', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'standardNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getPropertiesWithClassInfo(ast.children); | ||
expect(res.length).toBe(7); | ||
}); | ||
|
||
it('getConstructorPropertiesWithClassInfo', () => { | ||
const file = fs.readFileSync(path.join(FIXTURES_DIR, 'standardNamespaceClass.php')); | ||
const ast = getterSetterParser.getAst(file.toString()); | ||
const res = getterSetterParser.getConstructorPropertiesWithClassInfo(ast.children); | ||
expect(res.length).toBe(2); | ||
}); |
Oops, something went wrong.