Skip to content

Commit e8b4e98

Browse files
authored
Merge pull request #10 from leonhelmus/master
Added Template settings and made everything 7.1 compliant.
2 parents 27afeca + da0e9b6 commit e8b4e98

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+346
-410
lines changed

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"version": "1.7.0",
1313
"require": {
14-
"php": "^5.4 || ^7.1",
14+
"php": "^7.1",
1515
"composer-plugin-api": "^1.0"
1616
},
1717
"require-dev": {

files/file.template.settings.xml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project version="4">
3+
<component name="ExportableFileTemplateSettings">
4+
<default_templates>
5+
<template name="M2-Acl-XML.xml" reformat="false" live-template-enabled="true" />
6+
<template name="M2-Class.php" reformat="false" live-template-enabled="true" />
7+
<template name="M2-Class-Block.php" reformat="false" live-template-enabled="true" />
8+
<template name="M2-Class-Helper.php" reformat="false" live-template-enabled="true" />
9+
<template name="M2-Class-Observer.php" reformat="false" live-template-enabled="true" />
10+
<template name="M2-Class-ViewModel.php" reformat="false" live-template-enabled="true" />
11+
<template name="M2-Config-XML.xml" reformat="false" live-template-enabled="true" />
12+
<template name="M2-Db-schema-XML.xml" reformat="false" live-template-enabled="true" />
13+
<template name="M2-DI.xml" reformat="false" live-template-enabled="true" />
14+
<template name="M2-Extension-Attributes-XML.xml" reformat="false" live-template-enabled="true" />
15+
<template name="M2-Layout-XML.xml" reformat="false" live-template-enabled="true" />
16+
<template name="M2-Module-XML.xml" reformat="false" live-template-enabled="true" />
17+
<template name="M2-Registration.php" reformat="false" live-template-enabled="true" />
18+
<template name="M2-Sales-XML.xml" reformat="false" live-template-enabled="true" />
19+
<template name="M2-System-include-XML.xml" reformat="false" live-template-enabled="true" />
20+
<template name="M2-System-XML.xml" reformat="false" live-template-enabled="true" />
21+
</default_templates>
22+
<includes_templates>
23+
<template name="M2-PHP-File-Header.php" reformat="true" live-template-enabled="true" />
24+
<template name="M2-Settings.php" reformat="true" live-template-enabled="true" />
25+
<template name="M2-XML-File-Header.xml" reformat="true" live-template-enabled="true" />
26+
</includes_templates>
27+
</component>
28+
</project>
File renamed without changes.
File renamed without changes.

files/fileTemplates/includes/M2 PHP File Header.php

-5
This file was deleted.

files/fileTemplates/includes/M2 XML File Header.xml

-7
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#parse("M2 Settings")
2+
/**
3+
* Copyright © $Company. All rights reserved.
4+
* $Website
5+
*/
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
#set( $Company = "MediaCT" )
22
#set( $Vendor = "MediaCT" )
3+
#set( $Website = "https://www.mediact.nl")
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#parse("M2 Settings")
2+
<!--
3+
/**
4+
* Copyright © $Company. All rights reserved.
5+
* $Website
6+
*/
7+
-->

src/Environment.php

+23-9
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
* Copyright MediaCT. All rights reserved.
44
* https://www.mediact.nl
55
*/
6+
67
namespace Mediact\CodingStandard\PhpStorm;
78

89
use Composer\Composer;
@@ -14,22 +15,22 @@ class Environment implements EnvironmentInterface
1415
* @var FilesystemInterface
1516
*/
1617
private $ideConfigFilesystem;
17-
18+
/**
19+
* @var FilesystemInterface
20+
*/
21+
private $ideDefaultFilesystem;
1822
/**
1923
* @var FilesystemInterface
2024
*/
2125
private $defaultsFilesystem;
22-
2326
/**
2427
* @var FilesystemInterface
2528
*/
2629
private $projectFilesystem;
27-
2830
/**
2931
* @var IOInterface
3032
*/
3133
private $inputOutput;
32-
3334
/**
3435
* @var Composer
3536
*/
@@ -39,23 +40,26 @@ class Environment implements EnvironmentInterface
3940
* Constructor.
4041
*
4142
* @param FilesystemInterface $ideConfigFilesystem
43+
* @param FilesystemInterface $ideDefaultFileSystem
4244
* @param FilesystemInterface $defaultsFilesystem
4345
* @param FilesystemInterface $projectFilesystem
4446
* @param IOInterface $inputOutput
4547
* @param Composer $composer
4648
*/
4749
public function __construct(
4850
FilesystemInterface $ideConfigFilesystem,
51+
FilesystemInterface $ideDefaultFileSystem,
4952
FilesystemInterface $defaultsFilesystem,
5053
FilesystemInterface $projectFilesystem,
5154
IOInterface $inputOutput,
5255
Composer $composer
5356
) {
54-
$this->ideConfigFilesystem = $ideConfigFilesystem;
55-
$this->defaultsFilesystem = $defaultsFilesystem;
56-
$this->projectFilesystem = $projectFilesystem;
57-
$this->inputOutput = $inputOutput;
58-
$this->composer = $composer;
57+
$this->ideConfigFilesystem = $ideConfigFilesystem;
58+
$this->ideDefaultFilesystem = $ideDefaultFileSystem;
59+
$this->defaultsFilesystem = $defaultsFilesystem;
60+
$this->projectFilesystem = $projectFilesystem;
61+
$this->inputOutput = $inputOutput;
62+
$this->composer = $composer;
5963
}
6064

6165
/**
@@ -68,6 +72,16 @@ public function getIdeConfigFilesystem(): FilesystemInterface
6872
return $this->ideConfigFilesystem;
6973
}
7074

75+
/**
76+
* Get a filesystem for the IDE configuration.
77+
*
78+
* @return FilesystemInterface
79+
*/
80+
public function getIdeDefaultConfigFilesystem(): FilesystemInterface
81+
{
82+
return $this->ideDefaultFilesystem;
83+
}
84+
7185
/**
7286
* Get a filesystem for the default configuration.
7387
*

src/EnvironmentInterface.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright MediaCT. All rights reserved.
44
* https://www.mediact.nl
55
*/
6+
67
namespace Mediact\CodingStandard\PhpStorm;
78

89
use Composer\Composer;
@@ -17,6 +18,13 @@ interface EnvironmentInterface
1718
*/
1819
public function getIdeConfigFilesystem(): FilesystemInterface;
1920

21+
/**
22+
* Get a filesystem for the IDE Default configuration.
23+
*
24+
* @return FilesystemInterface
25+
*/
26+
public function getIdeDefaultConfigFilesystem(): FilesystemInterface;
27+
2028
/**
2129
* Get a filesystem for the default configuration.
2230
*

src/Filesystem.php

+22-14
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright MediaCT. All rights reserved.
44
* https://www.mediact.nl
@@ -16,7 +16,7 @@ class Filesystem implements FilesystemInterface
1616
/**
1717
* @var string
1818
*/
19-
private $root;
19+
private $root = '';
2020

2121
/**
2222
* Constructor.
@@ -25,7 +25,9 @@ class Filesystem implements FilesystemInterface
2525
*/
2626
public function __construct($root)
2727
{
28-
$this->root = rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
28+
if (! empty($root)) {
29+
$this->root = rtrim($root, DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR;
30+
}
2931
}
3032

3133
/**
@@ -35,7 +37,7 @@ public function __construct($root)
3537
*
3638
* @return bool
3739
*/
38-
public function has($path)
40+
public function has(string $path): bool
3941
{
4042
return file_exists($this->getPath($path));
4143
}
@@ -46,10 +48,9 @@ public function has($path)
4648
* @param string $path
4749
*
4850
* @return string
49-
*
5051
* @throws RuntimeException When the path is not readable.
5152
*/
52-
public function read($path)
53+
public function read(string $path): string
5354
{
5455
$path = $this->getPath($path);
5556
if (!is_readable($path) || !is_file($path)) {
@@ -66,10 +67,9 @@ public function read($path)
6667
* @param string $contents
6768
*
6869
* @return bool
69-
*
7070
* @throws RuntimeException When the path is not writable.
7171
*/
72-
public function put($path, $contents)
72+
public function put(string $path, string $contents): bool
7373
{
7474
$directory = dirname($path);
7575
$this->createDir($directory);
@@ -82,7 +82,7 @@ public function put($path, $contents)
8282
throw new RuntimeException($path . ' is not writable');
8383
}
8484

85-
return file_put_contents($path, $contents);
85+
return (bool) file_put_contents($path, $contents);
8686
}
8787

8888
/**
@@ -91,10 +91,9 @@ public function put($path, $contents)
9191
* @param string $path
9292
*
9393
* @return bool
94-
*
9594
* @throws RuntimeException When the directory can not be created.
9695
*/
97-
public function createDir($path)
96+
public function createDir(string $path): bool
9897
{
9998
$directory = $this->getPath($path);
10099
if (!is_dir($directory)) {
@@ -120,10 +119,9 @@ public function createDir($path)
120119
* @param string $path
121120
*
122121
* @return array
123-
*
124122
* @throws RuntimeException When the path is not a directory.
125123
*/
126-
public function listFiles($path = '')
124+
public function listFiles(string $path = ''): array
127125
{
128126
$directory = $this->getPath($path);
129127
if (!is_dir($directory)) {
@@ -165,7 +163,7 @@ public function listFiles($path = '')
165163
*
166164
* @return string
167165
*/
168-
private function getPath($path)
166+
private function getPath(string $path): string
169167
{
170168
return $this->root .
171169
ltrim(
@@ -177,4 +175,14 @@ private function getPath($path)
177175
DIRECTORY_SEPARATOR
178176
);
179177
}
178+
179+
/**
180+
* Get root
181+
*
182+
* @return string
183+
*/
184+
public function getRoot(): string
185+
{
186+
return $this->root;
187+
}
180188
}

src/FilesystemInterface.php

+12-5
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ interface FilesystemInterface
1515
*
1616
* @return bool
1717
*/
18-
public function has($path);
18+
public function has(string $path): bool;
1919

2020
/**
2121
* Read a path.
@@ -24,7 +24,7 @@ public function has($path);
2424
*
2525
* @return string
2626
*/
27-
public function read($path);
27+
public function read(string $path): string;
2828

2929
/**
3030
* Write contents to a path.
@@ -34,7 +34,7 @@ public function read($path);
3434
*
3535
* @return bool
3636
*/
37-
public function put($path, $contents);
37+
public function put(string $path, string $contents): bool;
3838

3939
/**
4040
* Create a directory if it does not exist.
@@ -43,7 +43,7 @@ public function put($path, $contents);
4343
*
4444
* @return bool
4545
*/
46-
public function createDir($path);
46+
public function createDir(string $path): bool;
4747

4848
/**
4949
* List contents of a directory.
@@ -52,5 +52,12 @@ public function createDir($path);
5252
*
5353
* @return array
5454
*/
55-
public function listFiles($path = '');
55+
public function listFiles(string $path = ''): array;
56+
57+
/**
58+
* Get the root that has been set.
59+
*
60+
* @return string
61+
*/
62+
public function getRoot(): string;
5663
}

src/Patcher/CodeStylePatcher.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright MediaCT. All rights reserved.
44
* https://www.mediact.nl
@@ -21,7 +21,7 @@ class CodeStylePatcher implements ConfigPatcherInterface
2121
*/
2222
public function patch(
2323
EnvironmentInterface $environment
24-
) {
24+
): void {
2525
$this->copyFile(
2626
$environment->getDefaultsFilesystem(),
2727
$environment->getIdeConfigFilesystem(),

src/Patcher/ConfigPatcher.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php declare(strict_types=1);
22
/**
33
* Copyright MediaCT. All rights reserved.
44
* https://www.mediact.nl
@@ -30,7 +30,9 @@ public function __construct(array $patchers = null)
3030
: [
3131
new CodeStylePatcher(),
3232
new FileTemplatesPatcher($xmlAccessor),
33-
new InspectionsPatcher($xmlAccessor)
33+
new InspectionsPatcher($xmlAccessor),
34+
new TemplateSettingsPatcher($xmlAccessor),
35+
new LiveTemplatesPatcher()
3436
];
3537
}
3638

@@ -43,7 +45,7 @@ public function __construct(array $patchers = null)
4345
*/
4446
public function patch(
4547
EnvironmentInterface $environment
46-
) {
48+
): void {
4749
foreach ($this->patchers as $patcher) {
4850
$patcher->patch($environment);
4951
}

0 commit comments

Comments
 (0)