Skip to content

Added a project resolver to decide which project is installed. Also a… #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
14 changes: 13 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## 2.4.0 - 2022-04-13
### Added
- A project resolver to decide which project is installed. Also added a config to overwrite the type used.
- Composer requirement which should have already been there.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could be more explicit here, as in

Fixed (we did not add a feature, we fixed a problem)

  • Added missing composer dependency to package X


### Changed
- Make patches independent on project type.
- Files mapping to make clear which platforms the files are used for.

### Fixed
- Issue where magento 2 IDE files are installed in different projects like `Alumio` or `Laravel`.

## 2.3.0 - 2021-03-10
### Added
- Copyright.
- Declare strict type.

### Changed
- Vendor name from Mediact to Youwe
- Vendor name from Mediact to Youwe
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"composer-plugin-api": "^1.0 || ^2.0"
},
"require-dev": {
"composer/composer": "@stable",
"ext-simplexml": "*",
"kint-php/kint": "@stable",
"mikey179/vfsstream": "^1.6"
"mikey179/vfsstream": "^1.6",
"phpunit/phpunit": "@stable"
},
"autoload": {
"psr-4": {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Youwe" />
<option name="myName" value="Global" />
<inspection_tool class="AmdModulesDependencies" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
<inspection_tool class="BadExpressionStatementJS" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="BladeControlDirectives" enabled="false" level="WARNING" enabled_by_default="false" />
Expand Down
7 changes: 7 additions & 0 deletions files/default/inspectionProfiles/profiles_settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<component name="InspectionProjectProfileManager">
<settings>
<option name="projectProfile" value="Global" />
<option name="PROJECT_PROFILE" value="Global" />
<version value="1.0" />
</settings>
</component>
7 changes: 0 additions & 7 deletions files/inspectionProfiles/profiles_settings.xml

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
16 changes: 15 additions & 1 deletion src/Environment.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ class Environment implements EnvironmentInterface
* @var Composer
*/
private $composer;
/** @var ProjectTypeResolver */
private $projectTypeResolver;

/**
* Constructor.
Expand All @@ -55,14 +57,16 @@ public function __construct(
FilesystemInterface $defaultsFilesystem,
FilesystemInterface $projectFilesystem,
IOInterface $inputOutput,
Composer $composer
Composer $composer,
ProjectTypeResolver $projectTypeResolver
) {
$this->ideConfigFilesystem = $ideConfigFilesystem;
$this->ideDefaultFilesystem = $ideDefaultFileSystem;
$this->defaultsFilesystem = $defaultsFilesystem;
$this->projectFilesystem = $projectFilesystem;
$this->inputOutput = $inputOutput;
$this->composer = $composer;
$this->projectTypeResolver = $projectTypeResolver;
}

/**
Expand Down Expand Up @@ -124,4 +128,14 @@ public function getComposer(): Composer
{
return $this->composer;
}

/**
* Get project type resolver.
*
* @return ProjectTypeResolver
*/
public function getProjectTypeResolver(): ProjectTypeResolver
{
return $this->projectTypeResolver;
}
}
7 changes: 7 additions & 0 deletions src/EnvironmentInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,11 @@ public function getInputOutput(): IOInterface;
* @return Composer
*/
public function getComposer(): Composer;

/**
* Get composer project type resolver.
*
* @return ProjectTypeResolver
*/
public function getProjectTypeResolver(): ProjectTypeResolver;
}
3 changes: 2 additions & 1 deletion src/InstallerPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ public function onNewCodeEvent(Event $event): void
new Filesystem($filesDir),
new Filesystem($projectDir),
$event->getIO(),
$event->getComposer()
$event->getComposer(),
new ProjectTypeResolver($event->getComposer())
)
);

Expand Down
2 changes: 1 addition & 1 deletion src/Patcher/CodeStylePatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public function patch(
$this->copyFile(
$environment->getDefaultsFilesystem(),
$environment->getIdeConfigFilesystem(),
'codeStyleSettings.xml'
'codeStyleSettings.xml'
);
}
}
34 changes: 26 additions & 8 deletions src/Patcher/ConfigPatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@
namespace Youwe\CodingStandard\PhpStorm\Patcher;

use Youwe\CodingStandard\PhpStorm\EnvironmentInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\Magento2\FileTemplatesPatcher as FileTemplatesPatcherMagento2;
use Youwe\CodingStandard\PhpStorm\Patcher\Magento2\LiveTemplatesPatcher;
use Youwe\CodingStandard\PhpStorm\Patcher\Magento2\TemplateSettingsPatcher;
use Youwe\CodingStandard\PhpStorm\XmlAccessor;

class ConfigPatcher implements ConfigPatcherInterface
{
/**
* @var ConfigPatcherInterface[]
* @var array
*/
private $patchers;

Expand All @@ -31,11 +34,16 @@ public function __construct(array $patchers = null)
$this->patchers = $patchers !== null
? $patchers
: [
new CodeStylePatcher(),
new FileTemplatesPatcher($xmlAccessor),
new InspectionsPatcher($xmlAccessor),
new TemplateSettingsPatcher($xmlAccessor),
new LiveTemplatesPatcher()
'default' => [
new CodeStylePatcher(),
new FileTemplatesPatcher($xmlAccessor),
new InspectionsPatcher($xmlAccessor)
],
'magento2' => [
new FileTemplatesPatcherMagento2(),
new TemplateSettingsPatcher($xmlAccessor),
new LiveTemplatesPatcher()
]
];
}

Expand All @@ -49,8 +57,18 @@ public function __construct(array $patchers = null)
public function patch(
EnvironmentInterface $environment
): void {
foreach ($this->patchers as $patcher) {
$patcher->patch($environment);
foreach ($this->patchers as $projectType => $patchers) {
foreach ($patchers as $patcher) {
if ($environment->getProjectTypeResolver()->resolve() === $projectType) {
$patcher->patch($environment);
} elseif ($projectType === 'default') {
/**
* Patches that are default are configured for all projects.
* TODO:: Add function to overwrite default patches.
**/
$patcher->patch($environment);
}
}
}
}
}
17 changes: 12 additions & 5 deletions src/Patcher/CopyFilesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
namespace Youwe\CodingStandard\PhpStorm\Patcher;

use Youwe\CodingStandard\PhpStorm\FilesystemInterface;
use Youwe\CodingStandard\PhpStorm\ProjectTypeResolver;

trait CopyFilesTrait
{
Expand All @@ -19,15 +20,17 @@ trait CopyFilesTrait
* @param FilesystemInterface $source
* @param FilesystemInterface $destination
* @param string $path
* @param string $type
*
* @return void
*/
private function copyDirectory(
FilesystemInterface $source,
FilesystemInterface $destination,
string $path
string $path,
string $type = ProjectTypeResolver::DEFAULT_PROJECT_TYPE
): void {
foreach ($source->listFiles($path) as $filePath) {
foreach ($source->listFiles($type . DIRECTORY_SEPARATOR . $path) as $filePath) {
$this->copyFile($source, $destination, $filePath);
}
}
Expand All @@ -38,17 +41,21 @@ private function copyDirectory(
* @param FilesystemInterface $source
* @param FilesystemInterface $destination
* @param string $path
* @param string $type
*
* @return void
*/
private function copyFile(
FilesystemInterface $source,
FilesystemInterface $destination,
string $path
string $path,
string $type = ProjectTypeResolver::DEFAULT_PROJECT_TYPE
): void {
$projectPath = $type . DIRECTORY_SEPARATOR . $path;

$destination->put(
$path,
$source->read($path)
$projectPath,
$source->read($projectPath)
);
}
}
4 changes: 2 additions & 2 deletions src/Patcher/InspectionsPatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class InspectionsPatcher implements ConfigPatcherInterface
use CopyFilesTrait;

public const PROJECT_PHPCS = 'phpcs.xml';
public const INSPECTION_PROFILE = 'inspectionProfiles/MediaCT.xml';
public const INSPECTION_PROFILE = 'inspectionProfiles/Global.xml';

/**
* @var XmlAccessorInterface
Expand Down Expand Up @@ -48,7 +48,7 @@ public function patch(
$this->copyDirectory(
$environment->getDefaultsFilesystem(),
$environment->getIdeConfigFilesystem(),
'inspectionProfiles'
'default/inspectionProfiles'
);

$this->setProjectProfiles($environment);
Expand Down
37 changes: 37 additions & 0 deletions src/Patcher/Magento2/FileTemplatesPatcher.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* Copyright Youwe. All rights reserved.
* https://www.youweagency.com
*/

declare(strict_types=1);

namespace Youwe\CodingStandard\PhpStorm\Patcher\Magento2;

use Youwe\CodingStandard\PhpStorm\EnvironmentInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\ConfigPatcherInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\CopyFilesTrait;

class FileTemplatesPatcher implements ConfigPatcherInterface
{
use CopyFilesTrait;

/**
* Patch the config.
*
* @param EnvironmentInterface $environment
*
* @return void
*/
public function patch(
EnvironmentInterface $environment
): void {
$this->copyDirectory(
$environment->getDefaultsFilesystem(),
$environment->getIdeConfigFilesystem(),
DIRECTORY_SEPARATOR . 'fileTemplates',
$environment->getProjectTypeResolver()->resolve()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

declare(strict_types=1);

namespace Youwe\CodingStandard\PhpStorm\Patcher;
namespace Youwe\CodingStandard\PhpStorm\Patcher\Magento2;

use Youwe\CodingStandard\PhpStorm\EnvironmentInterface;
use Youwe\CodingStandard\PhpStorm\FilesystemInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\ConfigPatcherInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\CopyFilesTrait;

class LiveTemplatesPatcher implements ConfigPatcherInterface
{
Expand All @@ -26,11 +27,13 @@ class LiveTemplatesPatcher implements ConfigPatcherInterface
public function patch(
EnvironmentInterface $environment
): void {
if (! empty($environment->getIdeDefaultConfigFilesystem()->getRoot())) {

if (!empty($environment->getIdeDefaultConfigFilesystem()->getRoot())) {
$this->copyDirectory(
$environment->getDefaultsFilesystem(),
$environment->getIdeDefaultConfigFilesystem(),
'templates'
'templates',
$environment->getProjectTypeResolver()->resolve()
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@

declare(strict_types=1);

namespace Youwe\CodingStandard\PhpStorm\Patcher;
namespace Youwe\CodingStandard\PhpStorm\Patcher\Magento2;

use Youwe\CodingStandard\PhpStorm\EnvironmentInterface;
use Youwe\CodingStandard\PhpStorm\FilesystemInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\ConfigPatcherInterface;
use Youwe\CodingStandard\PhpStorm\Patcher\CopyFilesTrait;
use Youwe\CodingStandard\PhpStorm\XmlAccessorInterface;

class TemplateSettingsPatcher implements ConfigPatcherInterface
Expand Down Expand Up @@ -70,15 +71,17 @@ public function patch(
public function patchFileTemplateSettings(
EnvironmentInterface $environment
): void {
if (!$environment->getIdeConfigFilesystem()->has('file.template.settings.xml')) {
$path = 'file.template.settings.xml';
if (!$environment->getIdeConfigFilesystem()->has($path)) {
$this->copyFile(
$environment->getDefaultsFilesystem(),
$environment->getIdeConfigFilesystem(),
'file.template.settings.xml'
$path,
$environment->getProjectTypeResolver()->resolve()
);
} else {
$xml = simplexml_load_string(
$environment->getIdeConfigFilesystem()->read('file.template.settings.xml')
$environment->getIdeConfigFilesystem()->read($path)
);

foreach ($this->getFileTemplates() as $xmlTag => $fileTemplateNames) {
Expand All @@ -101,7 +104,7 @@ public function patchFileTemplateSettings(
'live-template-enabled' => 'true'
]
);
$environment->getIdeConfigFilesystem()->put('file.template.settings.xml', $xml->asXML());
$environment->getIdeConfigFilesystem()->put($path, $xml->asXML());
}
}
}
Expand All @@ -120,7 +123,9 @@ public function patchIncludes(EnvironmentInterface $environment): void
if (!$environment->getIdeConfigFilesystem()->has("fileTemplates/includes/$fileName")) {
$environment->getIdeConfigFilesystem()->put(
"fileTemplates/includes/$fileName",
$environment->getDefaultsFilesystem()->read("includes/$fileName")
$environment->getDefaultsFilesystem()->read(
$environment->getProjectTypeResolver()->resolve(). DIRECTORY_SEPARATOR ."includes/$fileName"
)
);
}
}
Expand Down
Loading