Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ rebuild; it ships as **1.0.0 Alpha 4**, the successor of the 1.0.0 Alpha 3 relea
`HTTP/` line with PHP's built-in server). A file with a second status line, a setter, or a computed `header()`
argument is reported without a fix. The description states that the status code sent by the replacement is the
same.
- No deprecated PHP plugin API is left (JetBrains Plugin Verifier, 2026.2 and 2026.3: "2 usages of deprecated API"):
the exit-guard check reads a `throw …;` statement through `PhpThrowExpression` instead of `PhpThrow`, and
**ResultSetGuard** reads a declared return type through `Function.getTypeDeclaration()` instead of
`getReturnType()`. A throw on one side of `||` or `??` is still no exit guard.
- The plugin description says that install and update normally need no IDE restart; the IDE decides that per
install, and the verifier asks for a manual check.

## 1.0.0-alpha.5 — 1.0.0 Alpha 5 — Marketplace release 2026-10-26

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ class XoopsResultSetGuardInspection : XoopsInspection() {
}

private fun plainReturn(fn: Function, element: PsiElement): String? {
val declaredRaw = fn.returnType?.text?.replace(":", "")?.trim()?.lowercase()
val declaredRaw = fn.typeDeclaration?.text?.replace(":", "")?.trim()?.lowercase()
if (!declaredRaw.isNullOrBlank()) {
val nullable = declaredRaw.startsWith("?") || declaredRaw.split('|').any { it.trim() == "null" }
val declared = declaredRaw.removePrefix("?")
Expand Down
6 changes: 4 additions & 2 deletions src/main/kotlin/org/xoops/support/psi/Php.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import com.jetbrains.php.lang.psi.elements.PhpExit
import com.jetbrains.php.lang.psi.elements.PhpNamespace
import com.jetbrains.php.lang.psi.elements.PhpPsiElement
import com.jetbrains.php.lang.psi.elements.PhpReturn
import com.jetbrains.php.lang.psi.elements.PhpThrow
import com.jetbrains.php.lang.psi.elements.PhpThrowExpression
import com.jetbrains.php.lang.psi.elements.PhpUseList
import com.jetbrains.php.lang.psi.elements.Statement
import com.jetbrains.php.lang.psi.elements.StringLiteralExpression
Expand Down Expand Up @@ -268,7 +268,9 @@ object Php {
else -> body
}
if (last == null) return false
if (last is PhpReturn || last is PhpThrow) return true
// A `throw …;` statement starts with its throw expression; `$x ?? throw …` and `$ok || throw …` do not,
// and they leave only on one side.
if (last is PhpReturn || last.firstChild is PhpThrowExpression) return true
if (PsiTreeUtil.findChildOfType(last, PhpExit::class.java, false) != null) return true
val firstCall = PsiTreeUtil.findChildOfType(last, FunctionReference::class.java, false) ?: return false
if (isCall(firstCall, "redirect_header")) return true
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
<h3>Getting started</h3>
<p>Install the plugin and open a XOOPS project. Detection is automatic. You can set the Core Version and other
options under <b>Settings → Languages &amp; Frameworks → XOOPS Support</b>, and the inspections are listed
under <b>Settings → Editor → Inspections → XOOPS</b>. The plugin installs and updates without an IDE restart.</p>
under <b>Settings → Editor → Inspections → XOOPS</b>. The plugin is dynamic: it normally installs and updates without an IDE restart.</p>

<p><a href="https://github.com/XOOPS/phpstorm-plugin">Source, documentation and issues on GitHub</a></p>
]]></description>
Expand Down Expand Up @@ -89,7 +89,7 @@
<code>class/xoopsobject.php</code>, <code>xoopsmodule.php</code>, <code>xoopsuser.php</code> and <code>mimetypes.inc.php</code> stubs moved to
<code>kernel/</code> / <code>include/</code>; the eight deprecated <code>xoops_load()</code> short names (<code>'cache'</code> → <code>'xoopscache'</code> …);
and a new inspection for <code>$xoopsOption[…]</code> inside a function without <code>global $xoopsOption</code>.</li>
<li>Dynamic install and update without restart (language-constant cache is a project service).</li>
<li>Dynamic plugin: install and update normally need no restart (language-constant cache is a project service).</li>
<li>Settings page (Core Version override, auto-scan, startup balloon), <b>New → XOOPS Module…</b> scaffold with a legacy or hybrid layout (Helper, PSR-4 autoloader, Xmf admin side) whose output passes every inspection, Tools → XOOPS Support menu, and Ctrl+B / Find Usages on language constants used as strings or in Smarty templates - all carried over from Alpha 3 and rebuilt.</li>
</ul>
<h3>1.0.0 Alpha 3 (1.0.0-alpha.3)</h3>
Expand Down
2 changes: 1 addition & 1 deletion src/test/kotlin/org/xoops/support/NeverBreakTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class NeverBreakTest : BasePlatformTestCase() {
fun testVoidFunctionGetsABareReturn() {
val text = fixEverything("adslight", "index.php")
val voidFunctions = PsiTreeUtil.findChildrenOfType(myFixture.file, Function::class.java)
.filter { it.returnType?.text?.contains("void") == true }
.filter { it.typeDeclaration?.text?.contains("void") == true }
assertTrue("fixture lost its void functions", voidFunctions.isNotEmpty())
for (fn in voidFunctions) {
val valued = PsiTreeUtil.findChildrenOfType(fn, PhpReturn::class.java).filter { it.argument != null }
Expand Down
13 changes: 10 additions & 3 deletions src/test/kotlin/org/xoops/support/XoopsQuickFixTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -926,9 +926,16 @@ class XoopsQuickFixTest : BasePlatformTestCase() {
fun testPathContainmentCanonicalisedAndDisplayPaths() =
check(XoopsPathContainmentInspection(), "PathContainment/canonical", "class/logger/Paths.php", 2)

/** page_tablesfill.php: an isResultSet() exit above a `!$result` exit is no legacy guard. */
fun testResultSetGuardRedundantLegacyExitIsNotReported() =
check(XoopsResultSetGuardInspection(), "ResultSetGuard/redundant", "modules/demo/class/Redundant.php", 1)
/**
* page_tablesfill.php: an isResultSet() exit above a `!$result` exit is no legacy guard. A `throw …;` statement
* is an exit, a throw on one side of `||` is not.
*/

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Medium · Aggregate count hides wrong guards

When Php.terminates treats count()'s unconditional throw as non-exiting but conditionalThrow()'s one-sided throw as exiting, testResultSetGuardRedundantLegacyExitIsNotReported at XoopsQuickFixTest.kt:934 checks only the total of 2 problems. An extra report for count() and a missing report for conditionalThrow() cancel out, so the test passes with both guard classifications wrong.

Assert the expected findings for each fixture method or at each relevant location, rather than only the aggregate count.

Prompt for AI agents
In `src/test/kotlin/org/xoops/support/XoopsQuickFixTest.kt` at line 932:

**Aggregate count hides wrong guards**

When `Php.terminates` treats `count()`'s unconditional throw as non-exiting but `conditionalThrow()`'s one-sided throw as exiting, `testResultSetGuardRedundantLegacyExitIsNotReported` at `XoopsQuickFixTest.kt:934` checks only the total of 2 problems. An extra report for `count()` and a missing report for `conditionalThrow()` cancel out, so the test passes with both guard classifications wrong.

Assert the expected findings for each fixture method or at each relevant location, rather than only the aggregate count.

fun testResultSetGuardRedundantLegacyExitIsNotReported() {
check(XoopsResultSetGuardInspection(), "ResultSetGuard/redundant", "modules/demo/class/Redundant.php", 2)
val lines = myFixture.doHighlighting().filter { it.description?.startsWith("XOOPS:") == true }
.map { myFixture.editor.document.getLineNumber(it.startOffset) + 1 }.sorted()
assertEquals(listOf(33, 42), lines)
}

/** file_safety.php: the existence check in a previous try (every catch returns) dominates unlink(). */
fun testUnlinkCheckedInsidePreviousTry() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ public function count()
return $count;
}

/** Reported: `$this->strict || throw …` leaves only when strict is off, so the block is no exit guard. */
public function conditionalThrow()
{
$result = $this->db->query('SELECT COUNT(*) FROM t');
if (!$this->db->isResultSet($result)) {
$this->strict || throw new \RuntimeException('query failed');
}
[$count] = $this->db->fetchRow($result);

return $count;
}

/** Reported: only the legacy exit guards the fetch. */
public function legacy()
{
Expand Down
Loading