27 |
28 |
29 |
30 |
31 |
32 | false
33 |
34 |
35 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 |
2 |
3 | # PhpClean Changelog
4 | ## [2023.12.17]
5 | ### Fixed
6 | - #186 RedundantDocCommentTagInspection - Skip checking array shapes
7 |
8 |
9 | # PhpClean Changelog
10 | ## [2023.04.01]
11 | ### Fixed
12 | - #162 Skip "use assert" qf before variable declaration
13 | ### Added
14 | - Introduce new action - use named constructor
15 |
16 | ## [2022.08.30]
17 | ### Changed
18 | - #163 Skip "final check" for anonymous classes
19 | - #151 Fix property visibility inspection for php8.1
20 | - #156 Skip Virtual type check for generic types
21 |
22 | ## [2022.10.22]
23 | ### Changed
24 | - #143 [Fixed] Check automatic string typecast on methods only
25 |
26 |
--------------------------------------------------------------------------------
/LICENSE.md:
--------------------------------------------------------------------------------
1 | # The MIT License (MIT)
2 |
3 | Copyright (c) 2018 Ivan Shcherbak
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in
13 | all copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21 | THE SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # PhpClean - PhpStorm/IDEA plugin
2 |
3 | [](https://plugins.jetbrains.com/plugin/11272-phpclean)
4 | [](https://plugins.jetbrains.com/plugin/11272-phpclean)
5 | [](LICENSE.md)
6 |
7 |
8 |
9 | Static Code Analysis for PhpStorm and Intellij Idea.
10 |
11 | ## Installation
12 | Open IDE go to `Settings->Plugins->Marketplace` search for the `PhpClean`.
13 | Hit `install` button.
14 |
15 | 
16 |
17 | [- Inspections](#Inspections)
18 |
19 | [- Actions](#Actions)
20 |
21 |
22 |
23 | ## Inspections
24 | #### AssignMisused
25 | Detects assignment and comparison operators in one statement.
26 | ```php
27 | while (false !== $current = ldap_next_entry($con, $current)) {
28 | // ^^^ Hard to read this statements
29 | yield $this->getSingleEntry($con, $current);
30 | }
31 | ```
32 | #### ClassNameCollision
33 | Classes with same name in different namespaces can be confused.
34 | (Disabled by default)
35 | ```php
36 | namespace App {
37 | class User {}; // <- Class name collision with \Cli\User
38 | }
39 | namespace Cli {
40 | class User {}; // <- Class name collision with \App\User
41 | }
42 | ```
43 | #### DeprecatedDocTag
44 | You can deprecate some PhpDoc tags in your project.
45 | #### GlobalVariableUsage
46 | This inspection detects usages of global variables.
47 | ```php
48 | echo $_GET['name']; // <-- Global variable usage
49 | ```
50 | #### MethodCanBePrivate
51 | Protected methods can be converted to private.
52 | ```php
53 | final class User {
54 | protected function name() {} // <-- Method can be private
55 | }
56 | ```
57 | #### MethodShouldBeFinal
58 | Methods should be closed (make method or class final)
59 | ```php
60 | class User {
61 | public function name(): string { // <-- Method should be final
62 | return '';
63 | }
64 | }
65 | ```
66 | #### MethodVisibility
67 | Protected methods make our classes more open. Write private or public methods only.
68 | #### MissingParameterTypeDeclaration
69 | Always specify parameter type. This is a good practice.
70 | ```php
71 | class User {
72 | public function withName($name) {} // <-- Missing parameter type
73 | }
74 | ```
75 | #### MissingReturnType
76 | Always specify result type of the function.
77 | ```php
78 | function phrase() { // <-- Missing return type
79 | return 'hi';
80 | }
81 | ```
82 | #### ParentPropertyDeprecated
83 | Check if parent property is deprecated.
84 | ```php
85 | class A {
86 | /** @deprecated */
87 | protected $name;
88 | }
89 | class B extends A {
90 | protected $name; // <-- Warn about deprecation
91 | }
92 | ```
93 | #### ProhibitedClassExtend
94 | Classes marked with `@final` doc tag should not be extended
95 | ```php
96 | /**
97 | * @final
98 | */
99 | class User {};
100 |
101 | class Admin extends User {}; // <- Prohibited extentions of @final class User.
102 | ```
103 | #### PropertyAnnotation
104 | Properties that are not initialized in the constructor should be annotated as nullable.
105 | ```php
106 | class User {
107 | /** @var string */ // <-- Property is not annotated correctly. Add null type
108 | private $name;
109 | public function getName() { }
110 | public function setName(string $name) { }
111 | }
112 | ```
113 | #### PropertyCanBePrivate
114 | Protected properties can be converted to private.
115 | ```php
116 | class User {
117 | protected $user; // <-- Property can be private
118 | }
119 | ```
120 | #### RedundantDocCommentTag
121 | Types that are specified in the php can be omitted in the PhpDoc blocks
122 | ```php
123 | /**
124 | * @return void // <-- Redundant PhpDoc tag
125 | */
126 | function show(string $message): void {}
127 | ```
128 | #### ToStringCall
129 | Detect automatic type casting
130 | ```php
131 | class Hello {
132 | public function randomize(): self { /* ... */return $this; }
133 | public function __toString() { return 'Hi'; }
134 | }
135 | echo (new Hello())->randomize(); // <-- Deprecated __toString call
136 | ```
137 | #### VirtualTypeCheck
138 | Use assert to check variable type instead of doc comment.
139 | ```php
140 | /** @var User $user */ // <-- Use assert to check variable type
141 | assert($user instanceof User);
142 | ```
143 |
144 | ## Actions
145 | #### UseNamedConstructor
146 | Replace `new ClassName()` with selected named constructor.
147 |
148 | ```php
149 | class Text {
150 | public function __construct(string $name){ }
151 | public static fromName(string $n){}
152 | }
153 | ```
154 | Invoke `refactor this` on method name `fromName`
155 | and all new statements with this class will be changed
156 |
157 | ```php
158 | new Text('User') // old code
159 | Text::fromName('User') // new code
160 | ```
161 |
162 |
--------------------------------------------------------------------------------
/build.gradle.kts:
--------------------------------------------------------------------------------
1 | import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
2 |
3 | plugins {
4 | id("java")
5 | id("org.jetbrains.kotlin.jvm") version "2.1.10"
6 | id("org.jetbrains.intellij") version "1.17.4"
7 | id("org.jetbrains.changelog") version "2.2.1"
8 | // ktlint linter - read more: https://github.com/JLLeitschuh/ktlint-gradle
9 | // id("org.jlleitschuh.gradle.ktlint") version "10.1.0"
10 | }
11 | fun properties(key: String) = project.findProperty(key).toString()
12 |
13 | // Import variables from gradle.properties file
14 | val pluginGroup: String by project
15 | // `pluginName_` variable ends with `_` because of the collision with Kotlin magic getter in the `intellij` closure.
16 | // Read more about the issue: https://github.com/JetBrains/intellij-platform-plugin-template/issues/29
17 | val pluginName_: String by project
18 | val pluginVersion: String by project
19 | val pluginSinceBuild: String by project
20 | val pluginVerifierIdeVersions: String by project
21 | val intellijPublishChannel: String by project
22 | val intellijPublishToken: String by project
23 |
24 | val platformType: String by project
25 | val platformVersion: String by project
26 | val platformPlugins: String by project
27 | val platformDownloadSources: String by project
28 |
29 | group = pluginGroup
30 | version = pluginVersion
31 | println("version: $version")
32 | // Configure project's dependencies
33 | repositories {
34 | mavenCentral()
35 | }
36 |
37 | // Configure gradle-intellij-plugin plugin.
38 | // Read more: https://github.com/JetBrains/gradle-intellij-plugin
39 | intellij {
40 | pluginName.set(pluginName_)
41 | version.set(platformVersion)
42 | type.set(platformType)
43 | downloadSources.set(platformDownloadSources.toBoolean())
44 | updateSinceUntilBuild.set(true)
45 | // Plugin Dependencies. Uses `platformPlugins` property from the gradle.properties file.
46 | plugins.set(properties("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
47 | }
48 | dependencies {
49 | testImplementation(gradleTestKit())
50 | testImplementation(kotlin("test"))
51 | testImplementation(kotlin("test-junit"))
52 | }
53 |
54 | // Read more: https://github.com/JetBrains/gradle-changelog-plugin
55 | changelog {
56 | version.set(pluginVersion)
57 | headerParserRegex.set("""(\d+\.\d+\.\d+)""".toRegex())
58 | }
59 | tasks {
60 | properties("javaVersion").let {
61 | withType {
62 | sourceCompatibility = it
63 | targetCompatibility = it
64 | }
65 | withType {
66 | kotlinOptions.jvmTarget = it
67 | }
68 | }
69 |
70 | publishPlugin {
71 | token.set(intellijPublishToken)
72 | channels.set(listOf(intellijPublishChannel, "default").filter(String::isNotEmpty).take(1))
73 | }
74 | patchPluginXml {
75 | version.set(pluginVersion)
76 | sinceBuild.set(pluginSinceBuild)
77 | changeNotes.set(
78 | changelog.getLatest().toHTML()
79 | )
80 | }
81 |
82 | runPluginVerifier {
83 | ideVersions.set(
84 | properties("pluginVerifierIdeVersions")
85 | .split(',').map(String::trim).filter(String::isNotEmpty)
86 | )
87 | }
88 |
89 | register("copyInspections") {
90 | doLast {
91 | inspections().forEach {
92 | write(
93 | File("src/main/resources/inspectionDescriptions/" + it.file().name),
94 | it.content()
95 | )
96 | }
97 | }
98 | }
99 | register("checkReadme") {
100 | doLast {
101 | if (readmeFile().readText() != generatedReadmeContent(readmeFile())) {
102 | throw GradleException("Readme is not up to date")
103 | }
104 | }
105 | }
106 | register("updateReadme") {
107 | doLast {
108 | val readme = readmeFile()
109 | if (write(readme, generatedReadmeContent(readme))) {
110 | println("Readme updated")
111 | }
112 | }
113 | }
114 |
115 | named("test") {
116 | dependsOn("checkReadme")
117 | }
118 | named("buildPlugin") {
119 | dependsOn("copyInspections")
120 | }
121 | named("runIde") {
122 | dependsOn("copyInspections")
123 | }
124 | }
125 | tasks.getByName("buildSearchableOptions").onlyIf { false }
126 |
127 | // Custom functions
128 | fun write(file: File, content: String): Boolean {
129 | var result = false
130 | if (!file.exists()) {
131 | file.createNewFile()
132 | }
133 | if (file.readText() != content) {
134 | result = true
135 | file.writeText(content)
136 | }
137 | return result
138 | }
139 |
140 | class Descriptor(
141 | private val file: File,
142 | private val uid: String
143 | ) {
144 | fun uid() = uid
145 | fun file() = file
146 | fun content() = file.readText()
147 | fun short() = content()
148 | .replace(Regex("(.*)", RegexOption.DOT_MATCHES_ALL), "")
149 | .trim()
150 | }
151 |
152 | fun actions() = projectHtmlFiles("Action")
153 | fun inspections() = projectHtmlFiles("Inspection")
154 |
155 |
156 | fun generatedReadmeContent(readme: File): String =
157 | readme.readText().replace(
158 | Regex(".+", RegexOption.DOT_MATCHES_ALL), ""
159 | ) + "\n" + generateSections()
160 |
161 | fun readmeFile() = File("README.md")
162 | fun projectHtmlFiles(type: String) = File("src/main/kotlin/com/funivan/idea/phpClean")
163 | .walkTopDown()
164 | .filter { it.name.contains("${type}.html") }
165 | .map {
166 | Descriptor(
167 | File(it.path),
168 | it.name.replace("${type}.html", "")
169 | )
170 | }
171 |
172 | fun generateSections() = listOf(
173 | Pair("Inspections", inspections()),
174 | Pair("Actions", actions()),
175 | ).fold("") { acc, pair ->
176 | acc + "## ${pair.first}\n" +
177 | pair.second.sortedBy { it.uid() }
178 | .map {
179 | val description = it.short().replace("
", "```php").replace("
", "```")
180 | "#### ${it.uid()}\n$description\n"
181 | }
182 | .joinToString("") +
183 | "\n"
184 | }
185 |
--------------------------------------------------------------------------------
/gradle.properties:
--------------------------------------------------------------------------------
1 | pluginGroup = com.funivan.idea.phpClean
2 | pluginName_ = PhpClean
3 | name = PhpClean
4 | pluginVersion = 2023.12.17
5 | pluginSinceBuild = 2022.2.3
6 | #pluginUntilBuild = 203.*
7 | # Plugin Verifier integration -> https://github.com/JetBrains/gradle-intellij-plugin#plugin-verifier-dsl
8 | # See https://jb.gg/intellij-platform-builds-list for available build versions
9 | pluginVerifierIdeVersions = 2022.3.2
10 | platformType = IU
11 | platformVersion = 2022.2.3
12 | platformDownloadSources = true
13 | # Plugin Dependencies -> https://plugins.jetbrains.com/docs/intellij/plugin-dependencies.html
14 | platformPlugins = com.intellij.java, com.jetbrains.php:222.4345.15
15 | javaVersion = 17
16 | # Opt-out flag for bundling Kotlin standard library.
17 | # See https://kotlinlang.org/docs/reference/using-gradle.html#dependency-on-the-standard-library for details.
18 | kotlin.stdlib.default.dependency = false
19 |
20 | # Publish configuration
21 | intellijPublishChannel=""
22 | intellijPublishToken=""
23 |
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/funivan/PhpClean/945e8e5b401999f2dc5d115b5d83ef4460a467d2/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | distributionBase=GRADLE_USER_HOME
2 | distributionPath=wrapper/dists
3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-all.zip
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 |
--------------------------------------------------------------------------------
/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env sh
2 |
3 | #
4 | # Copyright 2015 the original author or authors.
5 | #
6 | # Licensed under the Apache License, Version 2.0 (the "License");
7 | # you may not use this file except in compliance with the License.
8 | # You may obtain a copy of the License at
9 | #
10 | # https://www.apache.org/licenses/LICENSE-2.0
11 | #
12 | # Unless required by applicable law or agreed to in writing, software
13 | # distributed under the License is distributed on an "AS IS" BASIS,
14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 | # See the License for the specific language governing permissions and
16 | # limitations under the License.
17 | #
18 |
19 | ##############################################################################
20 | ##
21 | ## Gradle start up script for UN*X
22 | ##
23 | ##############################################################################
24 |
25 | # Attempt to set APP_HOME
26 | # Resolve links: $0 may be a link
27 | PRG="$0"
28 | # Need this for relative symlinks.
29 | while [ -h "$PRG" ] ; do
30 | ls=`ls -ld "$PRG"`
31 | link=`expr "$ls" : '.*-> \(.*\)$'`
32 | if expr "$link" : '/.*' > /dev/null; then
33 | PRG="$link"
34 | else
35 | PRG=`dirname "$PRG"`"/$link"
36 | fi
37 | done
38 | SAVED="`pwd`"
39 | cd "`dirname \"$PRG\"`/" >/dev/null
40 | APP_HOME="`pwd -P`"
41 | cd "$SAVED" >/dev/null
42 |
43 | APP_NAME="Gradle"
44 | APP_BASE_NAME=`basename "$0"`
45 |
46 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
47 | DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
48 |
49 | # Use the maximum available, or set MAX_FD != -1 to use that value.
50 | MAX_FD="maximum"
51 |
52 | warn () {
53 | echo "$*"
54 | }
55 |
56 | die () {
57 | echo
58 | echo "$*"
59 | echo
60 | exit 1
61 | }
62 |
63 | # OS specific support (must be 'true' or 'false').
64 | cygwin=false
65 | msys=false
66 | darwin=false
67 | nonstop=false
68 | case "`uname`" in
69 | CYGWIN* )
70 | cygwin=true
71 | ;;
72 | Darwin* )
73 | darwin=true
74 | ;;
75 | MINGW* )
76 | msys=true
77 | ;;
78 | NONSTOP* )
79 | nonstop=true
80 | ;;
81 | esac
82 |
83 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
84 |
85 |
86 | # Determine the Java command to use to start the JVM.
87 | if [ -n "$JAVA_HOME" ] ; then
88 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
89 | # IBM's JDK on AIX uses strange locations for the executables
90 | JAVACMD="$JAVA_HOME/jre/sh/java"
91 | else
92 | JAVACMD="$JAVA_HOME/bin/java"
93 | fi
94 | if [ ! -x "$JAVACMD" ] ; then
95 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
96 |
97 | Please set the JAVA_HOME variable in your environment to match the
98 | location of your Java installation."
99 | fi
100 | else
101 | JAVACMD="java"
102 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
103 |
104 | Please set the JAVA_HOME variable in your environment to match the
105 | location of your Java installation."
106 | fi
107 |
108 | # Increase the maximum file descriptors if we can.
109 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
110 | MAX_FD_LIMIT=`ulimit -H -n`
111 | if [ $? -eq 0 ] ; then
112 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
113 | MAX_FD="$MAX_FD_LIMIT"
114 | fi
115 | ulimit -n $MAX_FD
116 | if [ $? -ne 0 ] ; then
117 | warn "Could not set maximum file descriptor limit: $MAX_FD"
118 | fi
119 | else
120 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
121 | fi
122 | fi
123 |
124 | # For Darwin, add options to specify how the application appears in the dock
125 | if $darwin; then
126 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
127 | fi
128 |
129 | # For Cygwin or MSYS, switch paths to Windows format before running java
130 | if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
131 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
132 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
133 |
134 | JAVACMD=`cygpath --unix "$JAVACMD"`
135 |
136 | # We build the pattern for arguments to be converted via cygpath
137 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
138 | SEP=""
139 | for dir in $ROOTDIRSRAW ; do
140 | ROOTDIRS="$ROOTDIRS$SEP$dir"
141 | SEP="|"
142 | done
143 | OURCYGPATTERN="(^($ROOTDIRS))"
144 | # Add a user-defined pattern to the cygpath arguments
145 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
146 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
147 | fi
148 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
149 | i=0
150 | for arg in "$@" ; do
151 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
152 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
153 |
154 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
155 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
156 | else
157 | eval `echo args$i`="\"$arg\""
158 | fi
159 | i=`expr $i + 1`
160 | done
161 | case $i in
162 | 0) set -- ;;
163 | 1) set -- "$args0" ;;
164 | 2) set -- "$args0" "$args1" ;;
165 | 3) set -- "$args0" "$args1" "$args2" ;;
166 | 4) set -- "$args0" "$args1" "$args2" "$args3" ;;
167 | 5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
168 | 6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
169 | 7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
170 | 8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
171 | 9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
172 | esac
173 | fi
174 |
175 | # Escape application args
176 | save () {
177 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
178 | echo " "
179 | }
180 | APP_ARGS=`save "$@"`
181 |
182 | # Collect all arguments for the java command, following the shell quoting and substitution rules
183 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
184 |
185 | exec "$JAVACMD" "$@"
186 |
--------------------------------------------------------------------------------
/gradlew.bat:
--------------------------------------------------------------------------------
1 | @rem
2 | @rem Copyright 2015 the original author or authors.
3 | @rem
4 | @rem Licensed under the Apache License, Version 2.0 (the "License");
5 | @rem you may not use this file except in compliance with the License.
6 | @rem You may obtain a copy of the License at
7 | @rem
8 | @rem https://www.apache.org/licenses/LICENSE-2.0
9 | @rem
10 | @rem Unless required by applicable law or agreed to in writing, software
11 | @rem distributed under the License is distributed on an "AS IS" BASIS,
12 | @rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | @rem See the License for the specific language governing permissions and
14 | @rem limitations under the License.
15 | @rem
16 |
17 | @if "%DEBUG%" == "" @echo off
18 | @rem ##########################################################################
19 | @rem
20 | @rem Gradle startup script for Windows
21 | @rem
22 | @rem ##########################################################################
23 |
24 | @rem Set local scope for the variables with windows NT shell
25 | if "%OS%"=="Windows_NT" setlocal
26 |
27 | set DIRNAME=%~dp0
28 | if "%DIRNAME%" == "" set DIRNAME=.
29 | set APP_BASE_NAME=%~n0
30 | set APP_HOME=%DIRNAME%
31 |
32 | @rem Resolve any "." and ".." in APP_HOME to make it shorter.
33 | for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
34 |
35 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
36 | set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
37 |
38 | @rem Find java.exe
39 | if defined JAVA_HOME goto findJavaFromJavaHome
40 |
41 | set JAVA_EXE=java.exe
42 | %JAVA_EXE% -version >NUL 2>&1
43 | if "%ERRORLEVEL%" == "0" goto execute
44 |
45 | echo.
46 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
47 | echo.
48 | echo Please set the JAVA_HOME variable in your environment to match the
49 | echo location of your Java installation.
50 |
51 | goto fail
52 |
53 | :findJavaFromJavaHome
54 | set JAVA_HOME=%JAVA_HOME:"=%
55 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
56 |
57 | if exist "%JAVA_EXE%" goto execute
58 |
59 | echo.
60 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
61 | echo.
62 | echo Please set the JAVA_HOME variable in your environment to match the
63 | echo location of your Java installation.
64 |
65 | goto fail
66 |
67 | :execute
68 | @rem Setup the command line
69 |
70 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
71 |
72 |
73 | @rem Execute Gradle
74 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
75 |
76 | :end
77 | @rem End local scope for the variables with windows NT shell
78 | if "%ERRORLEVEL%"=="0" goto mainEnd
79 |
80 | :fail
81 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
82 | rem the _cmd.exe /c_ return code!
83 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
84 | exit /b 1
85 |
86 | :mainEnd
87 | if "%OS%"=="Windows_NT" endlocal
88 |
89 | :omega
90 |
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = name
--------------------------------------------------------------------------------
/src/main/kotlin/com/funivan/idea/phpClean/actions/useNamedConstructor/NamedConstructorUsageViewDescriptor.kt:
--------------------------------------------------------------------------------
1 | package com.funivan.idea.phpClean.actions.useNamedConstructor
2 |
3 | import com.intellij.usageView.UsageViewBundle
4 | import com.intellij.usageView.UsageViewDescriptor
5 | import com.jetbrains.php.lang.psi.elements.Method
6 |
7 | class NamedConstructorUsageViewDescriptor(
8 | val constructor: Method,
9 | val target: Method
10 | ) : UsageViewDescriptor {
11 | override fun getElements() =
12 | arrayOf(constructor)
13 |
14 | override fun getProcessedElementsHeader() =
15 | "Use named constructor: " + target.name
16 |
17 | override fun getCodeReferencesText(usagesCount: Int, filesCount: Int) =
18 | UsageViewBundle.getReferencesString(usagesCount, filesCount)
19 | }
20 |
--------------------------------------------------------------------------------
/src/main/kotlin/com/funivan/idea/phpClean/actions/useNamedConstructor/UseNamedConstructorAction.html:
--------------------------------------------------------------------------------
1 | Replace `new ClassName()` with selected named constructor.
2 |
3 |
4 | class Text {
5 | public function __construct(string $name){ }
6 | public static fromName(string $n){}
7 | }
8 |
9 | Invoke `refactor this` on method name `fromName`
10 | and all new statements with this class will be changed
11 |
12 |
13 | new Text('User') // old code
14 | Text::fromName('User') // new code
15 |
4 | namespace App {
5 | class User {}; // <- Class name collision with \Cli\User
6 | }
7 | namespace Cli {
8 | class User {}; // <- Class name collision with \App\User
9 | }
10 |
3 | class User {
4 | /** @var string */ // <-- Property is not annotated correctly. Add null type
5 | private $name;
6 | public function getName() { }
7 | public function setName(string $name) { }
8 | }
9 |