Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,16 @@ These are the default options for `grumphp`. All are optional and you can overri
```

This runs `grumphp run` on the code base.

### phpstan

These are the default options for `phpstan`. All are optional and you can override these as per the [command line options of `phpstan`](https://phpstan.org/user-guide/command-line-usage).

```yaml
checks: |
phpstan:
configuration: ''
paths: []
```

This runs `phpstan` on the code base with the specified options. For the defaults to work, you must have a `phpstan.neon` configuration file in your codebase as [mentioned in the documentation](https://phpstan.org/user-guide/command-line-usage#running-without-arguments). Note that the default `phpstan.neon` as generated by [`axelerant/drupal-quality-checker`](https://github.com/axelerant/drupal-quality-checker) is valid for this purpose.
39 changes: 39 additions & 0 deletions __tests__/phpstan.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import phpstan from '../src/checks/phpstan'
import {expect, test} from '@jest/globals'

test('it returns defaults', () => {
expect(phpstan({}, 'web')).toEqual([
'phpstan'
])
})

test('it handles configuration', () => {
let command
command = phpstan(
{
configuration: 'phpstan.neon'
},
'web'
)
expect(command).toContain('--configuration phpstan.neon')
})

test('it can handle single and multiple paths', () => {
let command
command = phpstan(
{
paths: ['web/modules/custom']
},
'web'
)
expect(command).toContain('web/modules/custom')

command = phpstan(
{
paths: ['web/modules/custom', 'web/themes/custom']
},
'web'
)
expect(command).toContain('web/modules/custom')
expect(command).toContain('web/themes/custom')
})
27 changes: 26 additions & 1 deletion dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

16 changes: 16 additions & 0 deletions src/checks/phpstan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {PhpStanOptions} from '../types'

export default function phpstan(
options: PhpStanOptions,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
webRoot: string
): string[] {
const commandArray = ['phpstan']
if (options.configuration !== undefined) {
commandArray.push(`--configuration ${options.configuration}`)
}
if (options.paths !== undefined) {
commandArray.unshift(...options.paths)
}
return commandArray
}
4 changes: 3 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@ import grumphp from './checks/grumphp'
import phplint from './checks/phplint'
import phpcs from './checks/phpcs'
import phpmd from './checks/phpmd'
import phpstan from './checks/phpstan'

const availableChecks: {
[key: string]: CheckCallable
} = {
grumphp,
phplint,
phpcs,
phpmd
phpmd,
phpstan
}

async function run(): Promise<void> {
Expand Down
5 changes: 5 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,8 @@ export interface GrumPHPOptions {
testsuite?: string
tasks?: string[]
}

export interface PhpStanOptions {
configuration?: string
paths?: string[]
}