---
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 [`modernize`](/docs/rules/sets/modernize) set. Unsafe fix: it can change behaviour. Gated by 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)

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