Skip to content

Unguarded vendor/autoload.php include warns twice per request on every release install #266

Description

@rubenvdlinde

Summary

Application::register() does an unguarded include_once of a composer autoloader that a
released install does not have, emitting two PHP warnings on every request that boots the app.

// lib/AppInfo/Application.php
include_once __DIR__.'/../../vendor/autoload.php';

composer.json requires only php: ^8.3 — everything else is require-dev. So there are no
runtime composer dependencies and a production install legitimately ships no vendor/
directory
.

Evidence

On a clean Nextcloud 34 install with the app enabled, a handful of page loads produced 150 log
lines of:

include_once(/var/www/html/custom_apps/nldesign/lib/AppInfo/../../vendor/autoload.php):
  Failed to open stream: No such file or directory at .../lib/AppInfo/Application.php#100
include_once(): Failed opening '.../vendor/autoload.php' for inclusion (include_path=...)

include_once never fatals, so nothing is broken. The cost is that the app's log is mostly this,
which is noise in its own right and good cover for a warning someone needs to see. It also cost me
real time: while debugging an unrelated problem these were the only nldesign lines in the log, and
they read like the root cause.

Fix

$autoloader = __DIR__.'/../../vendor/autoload.php';
if (\file_exists($autoloader) === true) {
    include_once $autoloader;
}

Why this is an issue and not already a PR

I wrote exactly that patch and reverted it, because it correctly failed the coverage ratchet:

FAIL: coverage dropped by 0.04% against the merge base.
      merge base 3548/4424 -> head 3548/4426 statements.
      This change adds 2 statements. Adding code without tests drops coverage.

The guard adds two statements that no unit test covers — there is no test for
Application::register() at all. Landing it means either weakening a working gate or writing the
first unit test for register(), which needs a mocked IRegistrationContext and exercises the
whole registration body (capability, two event listeners, the OpenRegister autoloader prelude).
That is worth doing, but it is its own piece of work rather than a drive-by on a test-coverage PR.

So: the fix is known and one line; it needs an accompanying register() unit test to land without
defeating the ratchet.

Found while raising gate-19 e2e coverage (#265).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions