Skip to content
This repository was archived by the owner on May 29, 2026. It is now read-only.

fix(notifier): correct OCP\IL10N namespace + setParsedMessage param name#78

Merged
rubenvdlinde merged 1 commit into
developmentfrom
fix/notifier-il10n-namespace
May 1, 2026
Merged

fix(notifier): correct OCP\IL10N namespace + setParsedMessage param name#78
rubenvdlinde merged 1 commit into
developmentfrom
fix/notifier-il10n-namespace

Conversation

@rubenvdlinde

Copy link
Copy Markdown
Contributor

Why

`composer phpstan` ends with `|| echo 'PHPStan not installed, skipping...'` so its exit code is always 0 — failures are silently dropped on CI. Two real bugs in `Notifier.php` were therefore sitting unflagged.

What

1. `\OCP\L10N\IL10N` does not exist

The interface lives at `\OCP\IL10N` (`lib/public/IL10N.php` in the server). The deprecated `OCP\L10N\IL10N` was removed several Nextcloud versions ago, but 6 occurrences in `Notifier.php` still referenced it (3 `@param` docblocks + 3 type-hinted method signatures). At runtime, dependency injection would have failed the moment the first `dashboard_shared` or `dashboard_ownership_transferred` notification was rendered.

2. `setParsedMessage(subject: …)` is the wrong named argument

`OCP\Notification\INotification::setParsedMessage(string $message)` takes `$message`, not `$subject`. PHP strict mode would reject the call with `Unknown named parameter $subject`. Two callsites fixed (lines 178, 220).

Impact

Metric Before After
PHPStan errors in `Notifier.php` 4 0
Full-repo PHPStan errors 47 26
PHPCS on `Notifier.php` clean (after phpcbf for the docblock-width shift) clean
PHPUnit 354/354 (no regression) 354/354

The 17 `Call to method t() on an unknown class OCP\L10N\IL10N` errors that propagated through the file disappear because phpstan can now resolve `$l` to the real interface.

Test plan

  • `./vendor/bin/phpstan analyse lib/Notification/Notifier.php` clean
  • `./vendor/bin/phpcs --standard=phpcs.xml lib/Notification/Notifier.php` clean
  • `composer test:unit` 354/354 passing
  • CI `quality / PHP Quality (phpstan)` green
  • Manual smoke: trigger a dashboard_shared notification, confirm it renders end-to-end (was previously broken at the type-hint level)

Followups (out of scope, called out for visibility)

  • The `composer phpstan` script's `|| echo` swallow should be removed once the remaining 26 errors are resolved — otherwise the next push could turn the check red retroactively. Worth a one-liner PR after the cleanup batch lands.
  • Remaining 26 phpstan errors fall mostly into `DataResponse` generic-typing in `DashboardShareApiController` (~25 sites) and a handful of misc real bugs in `AdminTemplateService`/`FileService`.

@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/mydash @ a31eea2

Check PHP Vue Security License Tests
lint
phpcs
phpmd
psalm
phpstan
phpmetrics
eslint
stylelint
composer ✅ 100/100
npm ✅ 342/342
PHPUnit ⏭️
Newman ⏭️
Playwright ⏭️

Quality workflow — 2026-05-01 07:34 UTC

Download the full PDF report from the workflow artifacts.

PHPStan was silently passing on CI (the composer phpstan script swallows
its exit code via `|| echo 'PHPStan not installed, skipping...'`), so two
real bugs in Notifier.php had been sitting unflagged:

1. The L10N type-hints / docblocks referenced `\OCP\L10N\IL10N`, but
   that class doesn't exist — the actual interface lives at `\OCP\IL10N`
   (lib/public/IL10N.php in the server). Wrong type-hint meant DI would
   have failed at runtime as soon as a `dashboard_shared` notification
   was rendered. 6 occurrences fixed (2 sites × {docblock, signature}
   plus permissionLabel).

2. Two `setParsedMessage(subject: $x)` calls used the wrong named
   argument — INotification::setParsedMessage's parameter is
   `$message`, not `$subject`. Same wrong-named-arg pattern PHP's
   strict mode rejects with "Unknown named parameter".

After the fix, `phpstan analyse lib/Notification/Notifier.php` is clean
(was 4 errors), and the full-repo phpstan count drops 47 → 26 because
the IL10N typo was poisoning every `$l->t(...)` callsite downstream.

phpcbf-autofixed the docblock alignment that shifted as a side effect
of shortening `\OCP\L10N\IL10N` → `\OCP\IL10N` (5 chars narrower).
@rubenvdlinde rubenvdlinde force-pushed the fix/notifier-il10n-namespace branch from 2ee1526 to bd809fc Compare May 1, 2026 08:01
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/mydash @ 1f8ccf7

Check PHP Vue Security License Tests
lint
phpcs
phpmd
psalm
phpstan
phpmetrics
eslint
stylelint
composer ✅ 100/100
npm
PHPUnit
Newman
Playwright

Quality workflow — 2026-05-01 08:01 UTC

Download the full PDF report from the workflow artifacts.

@rubenvdlinde rubenvdlinde merged commit b819745 into development May 1, 2026
16 of 19 checks passed
@rubenvdlinde rubenvdlinde deleted the fix/notifier-il10n-namespace branch May 1, 2026 08:02
@github-actions

github-actions Bot commented May 1, 2026

Copy link
Copy Markdown
Contributor

Quality Report — ConductionNL/mydash @ 43579b2

Check PHP Vue Security License Tests
lint
phpcs
phpmd
psalm
phpstan
phpmetrics
eslint
stylelint
composer ✅ 100/100
npm ✅ 342/342
PHPUnit ⏭️
Newman ⏭️
Playwright ⏭️

Quality workflow — 2026-05-01 08:03 UTC

Download the full PDF report from the workflow artifacts.

rubenvdlinde added a commit that referenced this pull request May 1, 2026
PR #78 dropped phpstan from 47 → 26 by fixing the IL10N namespace
typo. This batch clears the rest in four contained groups and
removes the `|| echo` swallow from the composer script so future
regressions actually fail CI.

DashboardShareApiController (21): swap `DataResponse` →
`JSONResponse` throughout the controller, matching the pattern used
by every other passing controller in the app (DashboardApiController,
ResponseHelper). The two classes are wire-compatible (both extend
Response, same constructor signature, both serialise to JSON), but
phpstan can resolve the JSONResponse generics from the existing
docblocks while the bare DataResponse type was forcing it to
infer T = `array<string, string>` and reject the call.

AdminSettingMapper (2): the entity's setUpdatedAt() expects
`?string`, but setSetting() was passing a `DateTime` object.
Format to `Y-m-d H:i:s` to match the convention from
DashboardFactory::create().

AdminTemplateService (1): replace `Ramsey\Uuid\Uuid::uuid4()` with
the same `random_bytes`-based generator used by DashboardFactory.
Ramsey UUID is not a declared composer dep, so the previous code
would have crashed at runtime — this surfaced because phpstan
correctly couldn't resolve the class.

FileService (2): two `Node::nodeExists()` / `Node::newFile()` /
`Node::putContent()` calls were made on results of `Folder::get()`,
which returns the `Node` interface. Type-narrow with explicit
`instanceof Folder` / `instanceof File` checks (throwing
`RuntimeException` on the impossible-but-typed branch) so phpstan
can verify the methods exist. Side benefit: removes a stale
`@phpstan-ignore-next-line` that was silencing a real downstream
error.

composer.json: drop the `|| echo 'PHPStan not installed, skipping...'`
from the `phpstan` script. The `||` made every phpstan run exit 0,
so the CI quality job was reporting green even when phpstan failed
— exactly how the IL10N typo and the Ramsey-UUID call slipped through
review. Now `composer phpstan` propagates the real exit code.

Verified locally: phpstan `[OK] No errors`, phpcs clean across
49 files, phpunit 354/354 (the one pre-existing
DashboardFactoryTest::testCreateRespectsExplicitPermissionLevel
failure is fixed by PR #77 and out of scope here).
rubenvdlinde added a commit that referenced this pull request May 1, 2026
PR #78 dropped phpstan from 47 → 26 by fixing the IL10N namespace
typo. This batch clears the rest in four contained groups and
removes the `|| echo` swallow from the composer script so future
regressions actually fail CI.

DashboardShareApiController (21): swap `DataResponse` →
`JSONResponse` throughout the controller, matching the pattern used
by every other passing controller in the app (DashboardApiController,
ResponseHelper). The two classes are wire-compatible (both extend
Response, same constructor signature, both serialise to JSON), but
phpstan can resolve the JSONResponse generics from the existing
docblocks while the bare DataResponse type was forcing it to
infer T = `array<string, string>` and reject the call.

AdminSettingMapper (2): the entity's setUpdatedAt() expects
`?string`, but setSetting() was passing a `DateTime` object.
Format to `Y-m-d H:i:s` to match the convention from
DashboardFactory::create().

AdminTemplateService (1): replace `Ramsey\Uuid\Uuid::uuid4()` with
the same `random_bytes`-based generator used by DashboardFactory.
Ramsey UUID is not a declared composer dep, so the previous code
would have crashed at runtime — this surfaced because phpstan
correctly couldn't resolve the class.

FileService (2): two `Node::nodeExists()` / `Node::newFile()` /
`Node::putContent()` calls were made on results of `Folder::get()`,
which returns the `Node` interface. Type-narrow with explicit
`instanceof Folder` / `instanceof File` checks (throwing
`RuntimeException` on the impossible-but-typed branch) so phpstan
can verify the methods exist. Side benefit: removes a stale
`@phpstan-ignore-next-line` that was silencing a real downstream
error.

composer.json: drop the `|| echo 'PHPStan not installed, skipping...'`
from the `phpstan` script. The `||` made every phpstan run exit 0,
so the CI quality job was reporting green even when phpstan failed
— exactly how the IL10N typo and the Ramsey-UUID call slipped through
review. Now `composer phpstan` propagates the real exit code.

Verified locally: phpstan `[OK] No errors`, phpcs clean across
49 files, phpunit 354/354 (the one pre-existing
DashboardFactoryTest::testCreateRespectsExplicitPermissionLevel
failure is fixed by PR #77 and out of scope here).
rubenvdlinde added a commit that referenced this pull request May 3, 2026
…ame (#78)

PHPStan was silently passing on CI (the composer phpstan script swallows
its exit code via `|| echo 'PHPStan not installed, skipping...'`), so two
real bugs in Notifier.php had been sitting unflagged:

1. The L10N type-hints / docblocks referenced `\OCP\L10N\IL10N`, but
   that class doesn't exist — the actual interface lives at `\OCP\IL10N`
   (lib/public/IL10N.php in the server). Wrong type-hint meant DI would
   have failed at runtime as soon as a `dashboard_shared` notification
   was rendered. 6 occurrences fixed (2 sites × {docblock, signature}
   plus permissionLabel).

2. Two `setParsedMessage(subject: $x)` calls used the wrong named
   argument — INotification::setParsedMessage's parameter is
   `$message`, not `$subject`. Same wrong-named-arg pattern PHP's
   strict mode rejects with "Unknown named parameter".

After the fix, `phpstan analyse lib/Notification/Notifier.php` is clean
(was 4 errors), and the full-repo phpstan count drops 47 → 26 because
the IL10N typo was poisoning every `$l->t(...)` callsite downstream.

phpcbf-autofixed the docblock alignment that shifted as a side effect
of shortening `\OCP\L10N\IL10N` → `\OCP\IL10N` (5 chars narrower).
rubenvdlinde added a commit that referenced this pull request May 3, 2026
PR #78 dropped phpstan from 47 → 26 by fixing the IL10N namespace
typo. This batch clears the rest in four contained groups and
removes the `|| echo` swallow from the composer script so future
regressions actually fail CI.

DashboardShareApiController (21): swap `DataResponse` →
`JSONResponse` throughout the controller, matching the pattern used
by every other passing controller in the app (DashboardApiController,
ResponseHelper). The two classes are wire-compatible (both extend
Response, same constructor signature, both serialise to JSON), but
phpstan can resolve the JSONResponse generics from the existing
docblocks while the bare DataResponse type was forcing it to
infer T = `array<string, string>` and reject the call.

AdminSettingMapper (2): the entity's setUpdatedAt() expects
`?string`, but setSetting() was passing a `DateTime` object.
Format to `Y-m-d H:i:s` to match the convention from
DashboardFactory::create().

AdminTemplateService (1): replace `Ramsey\Uuid\Uuid::uuid4()` with
the same `random_bytes`-based generator used by DashboardFactory.
Ramsey UUID is not a declared composer dep, so the previous code
would have crashed at runtime — this surfaced because phpstan
correctly couldn't resolve the class.

FileService (2): two `Node::nodeExists()` / `Node::newFile()` /
`Node::putContent()` calls were made on results of `Folder::get()`,
which returns the `Node` interface. Type-narrow with explicit
`instanceof Folder` / `instanceof File` checks (throwing
`RuntimeException` on the impossible-but-typed branch) so phpstan
can verify the methods exist. Side benefit: removes a stale
`@phpstan-ignore-next-line` that was silencing a real downstream
error.

composer.json: drop the `|| echo 'PHPStan not installed, skipping...'`
from the `phpstan` script. The `||` made every phpstan run exit 0,
so the CI quality job was reporting green even when phpstan failed
— exactly how the IL10N typo and the Ramsey-UUID call slipped through
review. Now `composer phpstan` propagates the real exit code.

Verified locally: phpstan `[OK] No errors`, phpcs clean across
49 files, phpunit 354/354 (the one pre-existing
DashboardFactoryTest::testCreateRespectsExplicitPermissionLevel
failure is fixed by PR #77 and out of scope here).
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant