Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 90248b9

Browse files
committed
Add property statement type if php types enabled
1 parent b2a4d36 commit 90248b9

File tree

8 files changed

+43
-4
lines changed

8 files changed

+43
-4
lines changed

out/changePropertyType.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/changePropertyType.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace StarWars;
5+
6+
class Jedi
7+
{
8+
private $name;
9+
10+
public function __construct($name)
11+
{
12+
$this->name = $name;
13+
}
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
namespace StarWars;
5+
6+
class Jedi
7+
{
8+
private Name $name;
9+
10+
public function __construct(Name $name)
11+
{
12+
$this->name = $name;
13+
}
14+
}

out/test/suite/changePropertyType.test.js

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

out/test/suite/changePropertyType.test.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/changePropertyType.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import Property from './property';
33
import Class from './class';
4+
import { config } from './utils';
45

56
export function changePropertyType(editor: vscode.TextEditor, property: Property, newPropertyType: string, phpClass: Class) {
67
const document = editor.document;
@@ -29,7 +30,7 @@ export function changePropertyType(editor: vscode.TextEditor, property: Property
2930

3031
let newPropertyText = `\$${property.getName()}`;
3132

32-
if (propertyNode.type) {
33+
if (config('phpAddProperty.property.types') === true || propertyNode.type) {
3334
newPropertyText = `${newPropertyType} ${newPropertyText}`;
3435
}
3536

src/test/suite/changePropertyType.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ suite('Change Property Type', function () {
2222
test('Should change the property statement type if already exists', async () => {
2323
await runFixture('TypedPropertyStatement.php');
2424
});
25+
26+
test('Should change the property statement type if typed properties is enabled', async () => {
27+
await vscode.workspace.getConfiguration('phpAddProperty').update('property.types', true, true);
28+
await runFixture('PropertyWithoutType.php');
29+
});
2530
});
2631

2732
async function runFixture(fileName: string, cursorPosition?: vscode.Position) {

0 commit comments

Comments
 (0)