---
title: "lint/style/prefer-dirname-levels"
pagination: false
---

{/* Generated by scripts/gen-rule-docs.py. Edit mapping.toml, not this file. */}

<RuleId id="lint/style/prefer-dirname-levels" />

In the [`lint-strict`](/docs/rules/presets/lint-strict) preset. In Rector's [`rector/php70`](/docs/rules/sets/rector/php70) set. Unsafe fix: it can change behavior. Depends on `[php] version`.

## What it does

Replace nested dirname() calls with one call and a `$levels` argument.

## Configuration

```toml title="pun.toml"
[lint.rules]
"style/prefer-dirname-levels" = "error"
```

To skip it in some files, add an [override](/docs/configuration/pun-toml#lint) or a [`@pun-ignore-file`](/docs/configuration/ignore-comments) comment.

## Replaces

- [`combine_nested_dirname`](https://cs.symfony.com/doc/rules/function_notation/combine_nested_dirname.html) (php-cs-fixer, risky)
- [`MultiDirname`](https://getrector.com/rule-detail/multi-dirname-rector) (rector)

[More lint/style rules](/docs/rules/lint/style) · [Edit this page](https://github.com/shipfastlabs/pun/edit/main/crates/pun-config/rules/mapping.toml)
