{"record":{"id":"40e752456cba4a3f","repo":"rectorphp/rector","slug":"we-could-not-find-local-composer-json-to-determi","errorCode":null,"errorMessage":"We could not find local \"composer.json\" to determine your PHP version.%sPlease, fill the PHP version set in withPhpSets() manually.","messagePattern":"We could not find local \"composer\\.json\" to determine your PHP version\\.(.+?)Please, fill the PHP version set in withPhpSets\\(\\) manually\\.","errorType":"validation","errorClass":"InvalidConfigurationException","httpStatus":null,"severity":"error","filePath":"src/Php/PhpVersionResolver/ComposerJsonPhpVersionResolver.php","lineNumber":33,"sourceCode":"{\n    /**\n     * @var array<string, PhpVersion::*|null>\n     */\n    private static array $cachedPhpVersions = [];\n    /**\n     * @return PhpVersion::*\n     */\n    public static function resolveFromCwdOrFail(): int\n    {\n        // use composer.json PHP version\n        $projectComposerJsonFilePath = getcwd() . '/composer.json';\n        if (file_exists($projectComposerJsonFilePath)) {\n            $projectPhpVersion = self::resolve($projectComposerJsonFilePath);\n            if (is_int($projectPhpVersion)) {\n                return $projectPhpVersion;\n            }\n        }\n        throw new InvalidConfigurationException(sprintf('We could not find local \"composer.json\" to determine your PHP version.%sPlease, fill the PHP version set in withPhpSets() manually.', \\PHP_EOL));\n    }\n    /**\n     * @return PhpVersion::*|null\n     */\n    public static function resolve(string $composerJson): ?int\n    {\n        if (array_key_exists($composerJson, self::$cachedPhpVersions)) {\n            return self::$cachedPhpVersions[$composerJson];\n        }\n        $projectComposerJson = JsonFileSystem::readFilePath($composerJson);\n        // give this one a priority, as more generic one. see https://github.com/composer/composer/issues/7914\n        $requirePhpVersion = $projectComposerJson['require']['php'] ?? $projectComposerJson['require']['php-64bit'] ?? null;\n        if ($requirePhpVersion !== null) {\n            self::$cachedPhpVersions[$composerJson] = self::createIntVersionFromComposerVersion($requirePhpVersion);\n            return self::$cachedPhpVersions[$composerJson];\n        }\n        // see https://getcomposer.org/doc/06-config.md#platform\n        $platformPhp = $projectComposerJson['config']['platform']['php'] ?? null;","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/rectorphp/rector/blob/408fcb0ff1833e3d26cbc9b04c23a77565814a16/src/Php/PhpVersionResolver/ComposerJsonPhpVersionResolver.php#L15-L51","documentation":"ComposerJsonPhpVersionResolver::resolveFromCwdOrFail() infers the project's PHP version by reading getcwd() . '/composer.json' and its require.php entry. Despite the message wording, it throws both when composer.json is absent from the cwd AND when it exists but yields no integer PHP requirement (e.g. no require.php key).","triggerScenarios":"Running vendor/bin/rector from a subdirectory or a directory without composer.json while rector.php calls withPhpSets() with no arguments; or a composer.json whose require section lacks a 'php'/'php-64bit' entry (e.g. only ext-* requirements).","commonSituations":"CI steps that cd into build/ or bin/ before invoking rector; monorepo tooling that executes from the workspace root while the config lives per-package; a library composer.json that never declared a php constraint.","solutions":["Run rector from the directory that contains composer.json (usually the project root)","Add a php constraint to require: \"require\": {\"php\": \"^8.2\"}","Or stop relying on autodetection: pin the level explicitly with withPhpSets(php82: true) / withPhpLevel(PhpVersion::PHP_82)"],"exampleFix":"// before: rector.php relies on cwd detection\nreturn RectorConfig::configure()->withPhpSets();\n// run from build/ -> throws\n\n// after: explicit level, cwd no longer matters\nuse Rector\\ValueObject\\PhpVersion;\n\nreturn RectorConfig::configure()->withPhpLevel(PhpVersion::PHP_82);","handlingStrategy":"validation","validationCode":"// before relying on autodetection\n$composerJsonPath = getcwd() . '/composer.json';\nif (! is_file($composerJsonPath)) {\n    throw new RuntimeException('Run Rector from the project root, or set an explicit PHP level.');\n}\n$require = json_decode((string) file_get_contents($composerJsonPath), true)['require'] ?? [];\nif (! isset($require['php'])) {\n    throw new RuntimeException('composer.json has no require.php; set withPhpLevel() explicitly.');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Invoke rector from the project root in composer scripts and CI (composer-run scripts inherit the right cwd)","Pin the level explicitly in configs intended to run anywhere: withPhpLevel(PhpVersion::PHP_82)","Keep a php constraint in require of every package Rector analyzes"],"tags":["php","rector","composer-json","php-version","working-directory"],"backgroundTag":"missing-composer-json","analyzedSha":"408fcb0ff1833e3d26cbc9b04c23a77565814a16","analyzedAt":"2026-08-21T05:11:02.643Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}