PHPackages                             nazonohito51/require-path-fixer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. nazonohito51/require-path-fixer

ActiveLibrary

nazonohito51/require-path-fixer
===============================

Fix require/include path

v0.2.1(7y ago)115.7kMITPHPPHP &gt;=5.3.3

Since Apr 13Pushed 7y ago2 watchersCompare

[ Source](https://github.com/nazonohito51/require-path-fixer)[ Packagist](https://packagist.org/packages/nazonohito51/require-path-fixer)[ RSS](/packages/nazonohito51-require-path-fixer/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (4)Used By (0)

RequirePathFixer
================

[](#requirepathfixer)

Legacy php project have a large number of require statements(require/require\_once/include/include\_once). And since they are not homogeneous, it is difficult to collect them all. This library searches all require statements and modifies them to be homogeneous code.

[![Latest Stable Version](https://camo.githubusercontent.com/6552c631ee90c28aa4794af8680a1515b5c0a99a11ee2aedd8a067351190687b/68747470733a2f2f706f7365722e707567782e6f72672f6e617a6f6e6f6869746f35312f726571756972652d706174682d66697865722f76657273696f6e)](https://packagist.org/packages/nazonohito51/require-path-fixer)

```
// before
require_once 'path/to/file.php';
require_once __DIR__ . '/path/to/file.php';
require_once dirname(__FILE__).'/path/to/file.php';
require_once('../app_root/path/to/file.php');
require_once      (   'path/' .
     'to/'                                  .         'file.php'     );
require 'path/to/file.php';
include_once 'path/to/file.php';
include 'path/to/file.php';
require_once UNKNOWN_CONSTANT . 'path/to/file.php';

// after
require_once APP_ROOT . '/path/to/file.php';
require_once APP_ROOT . '/path/to/file.php';
require_once APP_ROOT . '/path/to/file.php';
require_once APP_ROOT . '/path/to/file.php';
require_once APP_ROOT . '/path/to/file.php';
require APP_ROOT . '/path/to/file.php';
include_once APP_ROOT . '/path/to/file.php';
include APP_ROOT . '/path/to/file.php';
require_once UNKNOWN_CONSTANT . 'path/to/file.php';
```

Installation
------------

[](#installation)

```
composer require "nazonohito51/require-path-fixer"

```

Usage
-----

[](#usage)

```
require_once __DIR__. '/vendor/autoload.php';
$fixer = new \RequirePathFixer\Fixer($inspectDirPath);   // It is strongly recommended that $inspectDirPath be a repository root.

$fixer->report($inspectDirPath, "APP_ROOT");    // Only reporting.
$fixer->fix($inspectDirPath, "APP_ROOT");       // Fix all files.
// The first argument of these methods is the base path of the modified statement.
// The second argument is a constant or method representing the base path.
// ex: "APP_ROOT", "Config::get('app.root')"
```

Advanced usage
--------------

[](#advanced-usage)

### Define constants and variables

[](#define-constants-and-variables)

The following statement will be not replaced, because it is unknown what path COMMON\_DIR is.

`require_once COMMON_DIR . '/path/to/file.php';`

If there is a constant or variable to be replaced, it is passed to the following method.

```
$fixer->addConstant('COMMON_DIR', '/path/to/common/dir/');   // COMMON_DIR will be replaced to '/path/to/common/dir/'
$fixer->addVariable('$smartyDir', '/path/to/smarty/dir/');   // $smartyDir will be replaced to '/path/to/smarty/dir/'
```

### Restrict modification target

[](#restrict-modification-target)

If you have files or directories you don't want to modify, use `addBlackList()`.

```
$fixer->addBlackList($inspectDirPath . '/vendor');
$fixer->addBlackList($inspectDirPath . '/tests');
```

Or if you want to modify only some files in the repository, use `addWhiteList()`. `addBlackList()` and `addWhiteList()` can be used at the same time.

```
$fixer->addWhiteList($inspectDirPath . '/app');
```

### Define current directory

[](#define-current-directory)

In PHP, the following statement (starting with '.' or '..') determines the path from the current directory.

`require_once './path/to/file.php';`

Details are written in the [PHP Manual](http://php.net/manual/en/function.include.php). If you want to define the current directory, use `setWorkingDir()`. When the current directory is defined, this library resolves the above statement from the current directory. However, originally the current directory changes depending on the entry point, and it also dynamically changes using `chdir()`. Please be careful when using it.

```
$fixer->setWorkingDir($inspectDirPath . '/public');
```

### Define include\_path

[](#define-include_path)

In PHP, the following statement (relative path) determines the path from the include\_path.

`require_once 'path/to/file.php';`

If you want to define the include\_path, use `setIncludePath()`. When include\_path is defined, this library resolves the above statement from include\_path. However, originally include\_path changes dynamically with `set_include_path()`. Please also be careful when using it.

```
$fixer->setIncludePath(".:{$inspectDirPath}/app");
```

About analysis logic
--------------------

[](#about-analysis-logic)

This library classifies all statements into seven types and converts them. Their types are `absolute`, `variable`, `relative`, `unique`, `working_dir`, `include_path` and `unexpected`.

### `absolute`

[](#absolute)

If the path is an absolute path, fix it to the path from the new base path.

```
// before
require_once __DIR__ . '/hoge/app_root/path/to/file.php';
require_once (dirname(__FILE__).'/../app_root/' .'path/to/file.php');

// after
require_once APP_ROOT . '/path/to/file.php';
require_once APP_ROOT . '/path/to/file.php';
```

### `variable`

[](#variable)

If the path can not be resolved, such as unknown variable or constant, do not convert.

```
// before
require_once UNKNOWN_CONSTANT . 'path/to/file.php';
require_once $unknownVariable . 'path/to/file.php';

// after
require_once UNKNOWN_CONSTANT . 'path/to/file.php';
require_once $unknownVariable . 'path/to/file.php';
```

### `relative`

[](#relative)

In the path is an relative path, basically it is determined only at runtime, so it can not be replaced. But this library somehow tries to guess the path. That's `unique`, `working_dir`, `include_path`. However, if neither can be guessed, it will not be converted. That's `relative`.

```
// before
require_once 'path/to/file.php';
require_once './path/to/file.php';
require_once '../path/to/file.php';
require_once COMMON_DIR . '/path/to/file.php';   // COMMON_DIR is './app_root/common'

// after
require_once 'path/to/file.php';
require_once './path/to/file.php';
require_once '../path/to/file.php';
require_once COMMON_DIR . '/path/to/file.php';
```

### `unique`

[](#unique)

In relative paths, if there is only one file in the repository that matches the path in statement, this library converts it to the path to that file.

```
// before
require_once 'path/to/file.php';    // There is only one file that matches '/path\/to\/file\.php$/'.
require_once './hoge/fuga.php';    // There is only one file that matches '/hoge\/fuga\.php$/'.
require_once '../foo/bar.php';    // There was no file that matched the '/foo\/bar\.php$/', or there were multiple files.

// after
require_once APP_ROOT . '/path/to/file.php';
require_once APP_ROOT . '/path/to/hoge/fuga.php';
require_once '../foo/bar.php';
```

### `working_dir`

[](#working_dir)

In relative paths starting with '.' or '..', if define current directory by `setWorkingDir()`, this library resolves the path from the current directory. And this library will not guess by `unique`.

```
$fixer->setWorkingDir($inspectDirPath . '/public');

// before
require_once './hoge/fuga.php';
require_once '../foo/bar.php';
require_once COMMON_DIR . '/path/to/file.php';   // COMMON_DIR is './app_root/common'

// after
require_once APP_ROOT . '/public/hoge/fuga.php';
require_once APP_ROOT . '/foo/bar.php';
require_once APP_ROOT . '/common/path/to/file.php';
```

### `include_path`

[](#include_path)

In relative paths not starting with '.' or '..', if define include\_path by `setIncludePath()`, this library resolves the path from the include\_path. And this library will not guess by `unique`.

```
$fixer->setIncludePath('.:' . $inspectDirPath . '/common');   // '.' will be replace current directory, but if it is not defined, '.' will be ignored

// before
require_once 'hoge/fuga.php';
require_once 'foo/bar.php';

// after
require_once APP_ROOT . '/common/hoge/fuga.php';
require_once APP_ROOT . '/common/foo/bar.php';
```

### `unexpected`

[](#unexpected)

The statement will be of this type if it does not fall under either type.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity24

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~16 days

Total

3

Last Release

2917d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/532a77dad4d5cddde332e8a579607c87c9b38d314f21912bbbf19699757ed5d6?d=identicon)[nazonohito51](/maintainers/nazonohito51)

---

Top Contributors

[![nazonohito51](https://avatars.githubusercontent.com/u/7877772?v=4)](https://github.com/nazonohito51 "nazonohito51 (72 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/nazonohito51-require-path-fixer/health.svg)

```
[![Health](https://phpackages.com/badges/nazonohito51-require-path-fixer/health.svg)](https://phpackages.com/packages/nazonohito51-require-path-fixer)
```

###  Alternatives

[symfony/framework-bundle

Provides a tight integration between Symfony components and the Symfony full-stack framework

3.6k235.4M9.6k](/packages/symfony-framework-bundle)[laravel/pennant

A simple, lightweight library for managing feature flags.

57311.1M53](/packages/laravel-pennant)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[coenjacobs/mozart

Composes all dependencies as a package inside a WordPress plugin

4723.6M20](/packages/coenjacobs-mozart)[api-platform/symfony

Symfony API Platform integration

323.2M67](/packages/api-platform-symfony)[acquia/orca

A tool for testing a company's software packages together in the context of a realistic, functioning, best practices Drupal build

32902.4k](/packages/acquia-orca)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
