Useful lua functions for php development. Mostly for personal use.
- neovim 0.6+
- treesitter with php grammar installed
Install the plugin using your favorite package manager. Packer example:
use {'pcyman/phptools.nvim', ft = 'php'}Run somewhere in your config:
require('phptools').setup()Generates getters and setters for property under cursor or for multiple properties (in visual mode)
Lua:
require'phptools.getset'.generate_getset() -- under cursor
require'phptools.getset'.generate_getset('v') --visual modeVim commands:
PhpToolsGetSet
PhpToolsGetSetVisual
Assumes properties have visibility and type specified:
private string $name;Creates a unit test for currently open class with classes in constructor mocked.
Lua:
lua require'phptools.unitgen'.generate_test()Vim commands:
PhpToolsGenTest
Assumptions:
- assumes prophecy for mocking
- assumes class is somewhere in the
srcdirectory in the project - assumes tests are somewhere in the
testsdirectory in the project - assumes
composer.jsonis located in the root of the working directory - assumes namespaces for the
/srcand/testsdirs are defined incomposer.json