1
0
mirror of https://github.com/flarum/core.git synced 2025-08-13 11:54:32 +02:00

Apply fixes from StyleCI

[ci skip] [skip ci]
This commit is contained in:
luceos
2021-04-20 23:51:17 +00:00
committed by StyleCI Bot
parent 008206738f
commit 3a1803ee0f
3 changed files with 29 additions and 33 deletions

View File

@@ -111,8 +111,8 @@ class ForumServiceProvider extends AbstractServiceProvider
}
}**/
$sources->addDirectory(__DIR__ . '/../../js/dist/forum');
$sources->addDirectory(__DIR__ . '/../../js/dist/common');
$sources->addDirectory(__DIR__.'/../../js/dist/forum');
$sources->addDirectory(__DIR__.'/../../js/dist/common');
$sources->addString(function () {
return $this->container->make(Formatter::class)->getJs();
@@ -120,7 +120,7 @@ class ForumServiceProvider extends AbstractServiceProvider
});
$assets->css(function (SourceCollector $sources) {
$sources->addFile(__DIR__ . '/../../less/forum.less');
$sources->addFile(__DIR__.'/../../less/forum.less');
$sources->addString(function () {
return $this->container->make(SettingsRepositoryInterface::class)->get('custom_less', '');
});
@@ -142,7 +142,7 @@ class ForumServiceProvider extends AbstractServiceProvider
*/
public function boot()
{
$this->loadViewsFrom(__DIR__ . '/../../views', 'flarum.forum');
$this->loadViewsFrom(__DIR__.'/../../views', 'flarum.forum');
$this->container->make('view')->share([
'translator' => $this->container->make(TranslatorInterface::class),
@@ -202,7 +202,7 @@ class ForumServiceProvider extends AbstractServiceProvider
{
$factory = $this->container->make(RouteHandlerFactory::class);
$callback = include __DIR__ . '/routes.php';
$callback = include __DIR__.'/routes.php';
$callback($routes, $factory);
}

View File

@@ -12,7 +12,6 @@ namespace Flarum\Frontend\Compiler;
use axy\sourcemap\SourceMap;
use Flarum\Frontend\Compiler\Source\FileSource;
use Flarum\Frontend\Compiler\Source\FolderSource;
use Illuminate\Support\Arr;
class JsCompiler extends RevisionCompiler
{
@@ -25,14 +24,14 @@ class JsCompiler extends RevisionCompiler
return false;
}
$directory = $this->name . '/';
$mapFile = $file . '.map';
$directory = $this->name.'/';
$mapFile = $file.'.map';
$map = new SourceMap();
$map->file = $mapFile;
$output = [];
if (!$this->type) {
if (! $this->type) {
$output[] = 'var module={};';
}
@@ -45,24 +44,22 @@ class JsCompiler extends RevisionCompiler
if ($source instanceof FolderSource) {
foreach ($content as $file) {
$filepath = $source->getPath() . '/' . $file;
$filepath = $source->getPath().'/'.$file;
if (is_dir($filepath)) {
$this->levelN($filepath, $source, $file);
} else {
if (pathinfo($filepath, PATHINFO_EXTENSION) !== 'js') {
$this->assetsDir->put($source->getDirectoryName() . '/' . $file, file_get_contents($filepath));
$this->assetsDir->put($source->getDirectoryName().'/'.$file, file_get_contents($filepath));
} else {
$content = file_get_contents($filepath);
$cacheDifferentiator = hash('crc32b', serialize(array_merge($source->getCacheDifferentiator(), [$content])));
$this->putFile($source->getDirectoryName() . '/' . $file, $cacheDifferentiator, $content);
$this->putFile($source->getDirectoryName().'/'.$file, $cacheDifferentiator, $content);
}
}
}
} else {
if ($source instanceof FileSource) {
$sourceMap = $source->getPath() . '.map';
$sourceMap = $source->getPath().'.map';
if (file_exists($sourceMap)) {
$map->concat($sourceMap, $line);
@@ -77,14 +74,14 @@ class JsCompiler extends RevisionCompiler
$cacheDifferentiator = hash('crc32b', serialize($output));
$this->putFile($this->name . '/' . $this->name .'-' . $this->type . '.js', $cacheDifferentiator, $output);
$this->putFile($this->name.'/'.$this->name.'-'.$this->type.'.js', $cacheDifferentiator, $output);
// Add a comment to the end of our file to point to the sourcemap
// we just constructed. We will then store the JS file and the map
// in our asset directory.
$output[] = '//# sourceMappingURL=' . $this->assetsDir->url($mapFile);
$output[] = '//# sourceMappingURL='.$this->assetsDir->url($mapFile);
$this->assetsDir->put($directory . $mapFile, json_encode($map, JSON_UNESCAPED_SLASHES));
$this->assetsDir->put($directory.$mapFile, json_encode($map, JSON_UNESCAPED_SLASHES));
return true;
}
@@ -93,11 +90,11 @@ class JsCompiler extends RevisionCompiler
{
$this->assetsDir->makeDirectory($file);
foreach (array_diff(scandir($filepath), ['.', '..']) as $levelNFile) {
$filepath2 = $filepath . '/' . $levelNFile;
$filepath2 = $filepath.'/'.$levelNFile;
if (is_dir($filepath2)) {
$this->levelN($filepath2, $source, $file . '/' . $levelNFile);
$this->levelN($filepath2, $source, $file.'/'.$levelNFile);
} else {
$this->assetsDir->put($source->getDirectoryName() . '/' . $file . '/' . $levelNFile, file_get_contents($filepath2));
$this->assetsDir->put($source->getDirectoryName().'/'.$file.'/'.$levelNFile, file_get_contents($filepath2));
}
}
}
@@ -107,7 +104,7 @@ class JsCompiler extends RevisionCompiler
*/
protected function format(string $string): string
{
return preg_replace('~//# sourceMappingURL.*$~m', '', $string) . "\n";
return preg_replace('~//# sourceMappingURL.*$~m', '', $string)."\n";
}
/**
@@ -117,7 +114,7 @@ class JsCompiler extends RevisionCompiler
{
parent::delete($file);
if ($this->assetsDir->has($mapFile = $file . '.map')) {
if ($this->assetsDir->has($mapFile = $file.'.map')) {
$this->assetsDir->delete($mapFile);
}
}

View File

@@ -111,7 +111,7 @@ class RevisionCompiler implements CompilerInterface
{
$revision = $this->getRevision();
if (!$revision) {
if (! $revision) {
$this->commit();
$revision = $this->getRevision();
@@ -131,10 +131,10 @@ class RevisionCompiler implements CompilerInterface
$urls = [];
if (!empty($appResources[$this->type])) {
if (! empty($appResources[$this->type])) {
foreach ($appResources[$this->type] as $revision => $target) {
$ext = pathinfo($target, PATHINFO_EXTENSION);
$file = substr_replace($target, '-' . $revision, -strlen($ext) - 1, 0);
$file = substr_replace($target, '-'.$revision, -strlen($ext) - 1, 0);
$urls[] = $this->assetsDir->url($file);
}
}
@@ -203,25 +203,24 @@ class RevisionCompiler implements CompilerInterface
*/
protected function putFile(string $location, $cacheDifferentiator, $content)
{
if ($this->assetsDir->has(static::REV_MANIFEST)) {
$manifest = json_decode($this->assetsDir->read(static::REV_MANIFEST), true);
} else {
$manifest = [];
}
if (!isset($manifest[$this->name])) {
if (! isset($manifest[$this->name])) {
$manifest[$this->name] = [];
}
if (!isset($manifest[$this->name][$this->type])) {
if (! isset($manifest[$this->name][$this->type])) {
$manifest[$this->name][$this->type] = [];
}
if ($location) {
$ext = pathinfo($location, PATHINFO_EXTENSION);
$filename = substr_replace($location, '-'.$cacheDifferentiator, -strlen($ext) - 1, 0);
$filename = substr_replace($location, '-'.$cacheDifferentiator, -strlen($ext) - 1, 0);
$this->assetsDir->put($filename, $content);
$manifest[$this->name][$this->type][$cacheDifferentiator] = $location;
@@ -262,9 +261,9 @@ class RevisionCompiler implements CompilerInterface
$path = $this->assetsDir->getAdapter()->getPathPrefix();
$files = array_diff(scandir($path), ['.', '..']);
foreach($files as $file) {
if (!in_array($file, $this->ignoredItems)) {
$filePath = $this->assetsDir->getAdapter()->getPathPrefix() . '/' . $file;
foreach ($files as $file) {
if (! in_array($file, $this->ignoredItems)) {
$filePath = $this->assetsDir->getAdapter()->getPathPrefix().'/'.$file;
if (is_dir($filePath)) {
$this->assetsDir->deleteDirectory($file);
} else {