Skip to content

Commit c576ff6

Browse files
Merge pull request #75 from raphaelstolt/lgtm-option
Initial LGTM implementation.
2 parents 84ce9f4 + 3624a2e commit c576ff6

File tree

12 files changed

+123
-4
lines changed

12 files changed

+123
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### v1.6.0 `201?-??-??`
44
- `Added`
55
- User can optionally generate .env environment files. Done by [@raphaelstolt](https://github.com/raphaelstolt).
6+
- User can optionally generate LGTM configuration files. Done by [@raphaelstolt](https://github.com/raphaelstolt).
67

78
#### v1.5.0 `2015-11-07`
89
- `Added`

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,5 +156,12 @@ The `--env` option will generate [.env](https://github.com/vlucas/phpdotenv) env
156156
construct generate jonathantorres/logger --env
157157
```
158158

159+
## Generate LGTM configuration files?
160+
The `--lgtm` option will generate [LGTM](https://lgtm.co) configuration files within the constructed project. There's no short option available.
161+
162+
```bash
163+
construct generate jonathantorres/logger --lgtm
164+
```
165+
159166
## Run tests
160167
Just run `composer test` from the project's root directory.

src/Commands/ConstructCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ protected function configure()
7979
$editorConfigDescription = 'Generate an EditorConfig configuration';
8080
$phpVersionDescription = 'Project minimun required php version (one of: ' . join(', ', $this->defaults->phpVersions) . ')';
8181
$environmentDescription = 'Generate .env environment files';
82+
$lgtmDescription = 'Generate LGTM configuration files';
8283

8384
$this->setName('generate');
8485
$this->setDescription('Generates a basic PHP project');
@@ -93,6 +94,7 @@ protected function configure()
9394
$this->addOption('editor-config', 'e', InputOption::VALUE_NONE, $editorConfigDescription);
9495
$this->addOption('php', null, InputOption::VALUE_OPTIONAL, $phpVersionDescription, '5.6.0');
9596
$this->addOption('env', null, InputOption::VALUE_NONE, $environmentDescription);
97+
$this->addOption('lgtm', null, InputOption::VALUE_NONE, $lgtmDescription);
9698
}
9799

98100
/**
@@ -116,6 +118,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
116118
$editorConfig = $input->getOption('editor-config');
117119
$phpVersion = $input->getOption('php');
118120
$environment = $input->getOption('env');
121+
$lgtm = $input->getOption('lgtm');
119122

120123
if (!$this->str->isValid($projectName)) {
121124
$output->writeln('<error>Warning: "' . $projectName . '" is not a valid project name, please use "vendor/project"</error>');
@@ -139,7 +142,8 @@ protected function execute(InputInterface $input, OutputInterface $output)
139142
$vagrant,
140143
$editorConfig,
141144
$phpVersion,
142-
$environment
145+
$environment,
146+
$lgtm
143147
);
144148

145149
$this->construct->generate($this->settings, new Git, new Script);

src/Construct.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ public function generate(Settings $settings, Git $git, Script $script)
134134
$this->environmentFiles();
135135
}
136136

137+
if ($this->settings->withLgtmConfiguration()) {
138+
$this->lgtmFiles();
139+
}
140+
137141
$this->travis();
138142
$this->license($git);
139143
$this->composer($git);
@@ -568,6 +572,27 @@ protected function environmentFiles()
568572
$this->exportIgnores[] = '.env';
569573
}
570574

575+
/**
576+
* Generate LGTM configuration files.
577+
*
578+
* @return void
579+
*/
580+
protected function lgtmFiles()
581+
{
582+
$this->file->copy(
583+
__DIR__ . '/stubs/MAINTAINERS.stub',
584+
$this->projectLower . '/' . 'MAINTAINERS'
585+
);
586+
587+
$this->file->copy(
588+
__DIR__ . '/stubs/lgtm.stub',
589+
$this->projectLower . '/' . '.lgtm'
590+
);
591+
592+
$this->exportIgnores[] = 'MAINTAINERS';
593+
$this->exportIgnores[] = '.lgtm';
594+
}
595+
571596
/**
572597
* Generate phpunit test/file/settings.
573598
*

src/Settings.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,13 @@ class Settings
8181
*/
8282
private $environmentFiles;
8383

84+
/**
85+
* Generate LGTM configuration files?
86+
*
87+
* @var boolean
88+
*/
89+
private $lgtmConfiguration;
90+
8491
/**
8592
* Initialize.
8693
*
@@ -95,6 +102,7 @@ class Settings
95102
* @param boolean $editorConfig Generate an EditorConfig file?
96103
* @param boolean $phpVersion The entered php version
97104
* @param boolean $environmentFiles Generate .env environment files?
105+
* @param boolean $lgtmConfiguration Generate LGTM configuration files?
98106
*
99107
* @return void
100108
*/
@@ -109,7 +117,8 @@ public function __construct(
109117
$vagrantfile,
110118
$editorConfig,
111119
$phpVersion,
112-
$environmentFiles
120+
$environmentFiles,
121+
$lgtmConfiguration
113122
) {
114123
$this->projectName = $projectName;
115124
$this->testingFramework = $testingFramework;
@@ -122,6 +131,7 @@ public function __construct(
122131
$this->editorConfig = $editorConfig;
123132
$this->phpVersion = $phpVersion;
124133
$this->environmentFiles = $environmentFiles;
134+
$this->lgtmConfiguration = $lgtmConfiguration;
125135
}
126136

127137
/**
@@ -233,4 +243,14 @@ public function withEnvironmentFiles()
233243
{
234244
return $this->environmentFiles;
235245
}
246+
247+
/**
248+
* Whether or not to create LGTM configuration files.
249+
*
250+
* @return boolean
251+
*/
252+
public function withLgtmConfiguration()
253+
{
254+
return $this->lgtmConfiguration;
255+
}
236256
}

src/stubs/MAINTAINERS.stub

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Firstname Familyname <firstname.familyname@mail.com> (@githubhandle)

src/stubs/lgtm.stub

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
approvals = 2
2+
pattern = "(?i)LGTM"

tests/ConstructTest.php

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ public function testBasicProjectIsGenerated()
6767
null,
6868
null,
6969
'5.6.0',
70+
null,
7071
null
7172
);
7273

@@ -97,6 +98,7 @@ public function testProjectGenerationWithBehat()
9798
null,
9899
null,
99100
'5.6.0',
101+
null,
100102
null
101103
);
102104

@@ -118,6 +120,7 @@ public function testProjectGenerationWithCodeception()
118120
null,
119121
null,
120122
'5.6.0',
123+
null,
121124
null
122125
);
123126

@@ -139,6 +142,7 @@ public function testProjectGenerationWithPhpSpec()
139142
null,
140143
null,
141144
'5.6.0',
145+
null,
142146
null
143147
);
144148

@@ -160,6 +164,7 @@ public function testProjectGenerationWithApacheLicense()
160164
null,
161165
null,
162166
'5.6.0',
167+
null,
163168
null
164169
);
165170

@@ -180,6 +185,7 @@ public function testProjectGenerationWithGpl2License()
180185
null,
181186
null,
182187
'5.6.0',
188+
null,
183189
null
184190
);
185191

@@ -200,6 +206,7 @@ public function testProjectGenerationWithGpl3License()
200206
null,
201207
null,
202208
'5.6.0',
209+
null,
203210
null
204211
);
205212

@@ -220,6 +227,7 @@ public function testProjectGenerationWithSpecifiedNamespace()
220227
null,
221228
null,
222229
'5.6.0',
230+
null,
223231
null
224232
);
225233

@@ -242,6 +250,7 @@ public function testProjectGenerationWithGitRepository()
242250
null,
243251
null,
244252
'5.6.0',
253+
null,
245254
null
246255
);
247256

@@ -262,6 +271,7 @@ public function testProjectGenerationWithCodingStandardsFixer()
262271
null,
263272
null,
264273
'5.6.0',
274+
null,
265275
null
266276
);
267277

@@ -283,6 +293,7 @@ public function testProjectGenerationWithComposerKeywords()
283293
null,
284294
null,
285295
'5.6.0',
296+
null,
286297
null
287298
);
288299

@@ -303,6 +314,7 @@ public function testProjectGenerationWithVagrant()
303314
true,
304315
null,
305316
'5.6.0',
317+
null,
306318
null
307319
);
308320

@@ -324,6 +336,7 @@ public function testProjectGenerationWithEditorConfig()
324336
null,
325337
true,
326338
'5.6.0',
339+
null,
327340
null
328341
);
329342

@@ -345,6 +358,7 @@ public function testProjectGenerationWithPhp54()
345358
null,
346359
null,
347360
'5.4.0',
361+
null,
348362
null
349363
);
350364

@@ -366,6 +380,7 @@ public function testProjectGenerationWithPhp55()
366380
null,
367381
null,
368382
'5.5.0',
383+
null,
369384
null
370385
);
371386

@@ -387,6 +402,7 @@ public function testProjectGenerationWithPhp56()
387402
null,
388403
null,
389404
'5.6.0',
405+
null,
390406
null
391407
);
392408

@@ -408,6 +424,7 @@ public function testProjectGenerationWithPhp7()
408424
null,
409425
null,
410426
'7.0.0',
427+
null,
411428
null
412429
);
413430

@@ -429,7 +446,8 @@ public function testProjectGenerationWithEnvironmentFiles()
429446
null,
430447
false,
431448
'5.6.0',
432-
true
449+
true,
450+
false
433451
);
434452

435453
$this->construct->generate($settings, $this->gitHelper, $this->scriptHelper);
@@ -439,6 +457,29 @@ public function testProjectGenerationWithEnvironmentFiles()
439457
$this->assertSame($this->getStub('with-env/composer'), $this->getFile('composer.json'));
440458
}
441459

460+
public function testProjectGenerationWithLgtmConfiguration()
461+
{
462+
$settings = new Settings(
463+
'jonathantorres/logger',
464+
'phpunit',
465+
'MIT',
466+
'Vendor\Project',
467+
null,
468+
null,
469+
null,
470+
null,
471+
false,
472+
'5.6.0',
473+
null,
474+
true
475+
);
476+
477+
$this->construct->generate($settings, $this->gitHelper, $this->scriptHelper);
478+
$this->assertSame($this->getStub('with-lgtm/maintainers'), $this->getFile('MAINTAINERS'));
479+
$this->assertSame($this->getStub('with-lgtm/lgtm'), $this->getFile('.lgtm'));
480+
$this->assertSame($this->getStub('with-lgtm/gitattributes'), $this->getFile('.gitattributes'));
481+
}
482+
442483
/**
443484
* Get expected changelog file.
444485
*

tests/SettingsTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ protected function setUp()
2222
false,
2323
false,
2424
'5.6.0',
25-
true
25+
true,
26+
false
2627
);
2728
}
2829

@@ -39,5 +40,6 @@ public function testSettingsAreRetrieved()
3940
$this->assertFalse($this->settings->withEditorConfig());
4041
$this->assertSame('5.6.0', $this->settings->getPhpVersion());
4142
$this->assertTrue($this->settings->withEnvironmentFiles());
43+
$this->assertFalse($this->settings->withLgtmConfiguration());
4244
}
4345
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
* text=auto
2+
3+
/.gitattributes export-ignore
4+
/.gitignore export-ignore
5+
/.lgtm export-ignore
6+
/.travis.yml export-ignore
7+
/CHANGELOG.md export-ignore
8+
/CONTRIBUTING.md export-ignore
9+
/LICENSE.md export-ignore
10+
/MAINTAINERS export-ignore
11+
/README.md export-ignore
12+
/phpunit.xml.dist export-ignore
13+
/tests export-ignore

0 commit comments

Comments
 (0)