The indentation package by Colin O'Dell is a PHP library to detect and manipulate indentation of strings and files:
Built a simple but useful PHP library this week 🙂 https://t.co/RCvUBF5HJQ— /dev/colinodell 💙💛 (@colinodell) March 17, 2022
This package is brand-new and I am not sure what the author's plans are long-term. I thought it was interesting enough to share if you need a package to detect (or change) the indentation type of a string or file:
1use ColinODell\Indentation\Indentation;23$indentation = Indentation::detect(file_get_contents('composer.json'));45$indentation->getAmount() === 4; // true6$indentation->getType() === Indentation::TYPE_SPACE; // true7(string)$indentation === ' '; // true
You can also change indentation using this package for file:
1use ColinODell\Indentation\Indentation;23$composerJson = file_get_contents('composer.json');4$composerJson = Indentation::change($composerJson, new Indentation(1, Indentation::TYPE_TAB));5file_put_contents('composer.json', $composerJson);
You can check out this package on GitHub at colinodell/indentation to learn more and experiment with it.