diff --git a/ecs.php b/ecs.php index 7b09884..b5fe0ae 100644 --- a/ecs.php +++ b/ecs.php @@ -11,4 +11,4 @@ $ecsConfig->parallel(); $ecsConfig->sets([SetList::CRAFT_CMS_4]); -}; \ No newline at end of file +}; diff --git a/src/Beam.php b/src/Beam.php index 2b17ca6..5d9b93d 100644 --- a/src/Beam.php +++ b/src/Beam.php @@ -10,16 +10,14 @@ namespace superbig\beam; -use superbig\beam\services\BeamService as BeamServiceService; -use superbig\beam\variables\BeamVariable; - use Craft; use craft\base\Plugin; -use craft\services\Plugins; -use craft\events\PluginEvent; -use craft\web\UrlManager; -use craft\web\twig\variables\CraftVariable; + use craft\events\RegisterUrlRulesEvent; +use craft\web\twig\variables\CraftVariable; +use craft\web\UrlManager; +use superbig\beam\services\BeamService as BeamServiceService; +use superbig\beam\variables\BeamVariable; use yii\base\Event; @@ -56,7 +54,7 @@ public function init() Event::on( UrlManager::class, UrlManager::EVENT_REGISTER_SITE_URL_RULES, - function (RegisterUrlRulesEvent $event) { + function(RegisterUrlRulesEvent $event) { $event->rules['beam/download'] = 'beam/default'; } ); @@ -64,7 +62,7 @@ function (RegisterUrlRulesEvent $event) { Event::on( UrlManager::class, UrlManager::EVENT_REGISTER_CP_URL_RULES, - function (RegisterUrlRulesEvent $event) { + function(RegisterUrlRulesEvent $event) { $event->rules['beam/download'] = 'beam/default'; } ); @@ -72,7 +70,7 @@ function (RegisterUrlRulesEvent $event) { Event::on( CraftVariable::class, CraftVariable::EVENT_INIT, - function (Event $event) { + function(Event $event) { /** @var CraftVariable $variable */ $variable = $event->sender; $variable->set('beam', BeamVariable::class); diff --git a/src/controllers/DefaultController.php b/src/controllers/DefaultController.php index 03baf42..4d1adb7 100644 --- a/src/controllers/DefaultController.php +++ b/src/controllers/DefaultController.php @@ -10,10 +10,10 @@ namespace superbig\beam\controllers; -use superbig\beam\Beam; - use Craft; + use craft\web\Controller; +use superbig\beam\Beam; use yii\web\NotFoundHttpException; /** @@ -23,7 +23,6 @@ */ class DefaultController extends Controller { - protected array|int|bool $allowAnonymous = ['index']; /** @@ -34,7 +33,7 @@ class DefaultController extends Controller public function actionIndex() { $request = Craft::$app->getRequest(); - $hash = $request->getRequiredParam('hash'); + $hash = $request->getRequiredParam('hash'); $config = Beam::$plugin->beamService->downloadHash($hash); @@ -42,7 +41,7 @@ public function actionIndex() throw new NotFoundHttpException(); } - $path = $config['path']; + $path = $config['path']; $filename = $config['filename']; return Craft::$app->getResponse()->sendFile($path, $filename, [ diff --git a/src/models/BeamModel.php b/src/models/BeamModel.php index 959de57..3646c67 100644 --- a/src/models/BeamModel.php +++ b/src/models/BeamModel.php @@ -10,11 +10,10 @@ namespace superbig\beam\models; -use superbig\beam\Beam; - -use Craft; use craft\base\Model; +use superbig\beam\Beam; + /** * @author Superbig * @package Beam @@ -71,7 +70,7 @@ public function getConfig(): array { return [ 'header' => $this->header, - 'rows' => $this->content, + 'rows' => $this->content, ]; } diff --git a/src/services/BeamService.php b/src/services/BeamService.php index 626cd13..43bb66e 100644 --- a/src/services/BeamService.php +++ b/src/services/BeamService.php @@ -10,16 +10,14 @@ namespace superbig\beam\services; +use Craft; +use craft\base\Component; use craft\helpers\FileHelper; -use craft\helpers\Path; use craft\helpers\StringHelper; -use craft\helpers\UrlHelper; -use superbig\beam\Beam; -use Craft; -use craft\base\Component; +use craft\helpers\UrlHelper; use League\Csv\Writer; -use League\Csv\Reader; +use superbig\beam\Beam; use superbig\beam\models\BeamModel; use XLSXWriter; use yii\base\ErrorException; @@ -27,7 +25,6 @@ use yii\base\ExitException; use yii\base\InvalidConfigException; use yii\base\InvalidRouteException; -use yii\web\Response; /** * @author Superbig @@ -51,7 +48,7 @@ public function create($config = []) */ public function csv(BeamModel $model): void { - $header = $model->header; + $header = $model->header; $content = $model->content; if (empty($header) && empty($content)) { @@ -87,8 +84,8 @@ public function csv(BeamModel $model): void public function xlsx(BeamModel $model): void { $tempPath = Craft::$app->path->getTempPath() . DIRECTORY_SEPARATOR . 'beam' . DIRECTORY_SEPARATOR; - $header = $model->header; - $content = $model->content; + $header = $model->header; + $content = $model->content; if (empty($header) && empty($content)) { return; @@ -99,7 +96,7 @@ public function xlsx(BeamModel $model): void } // Load the CSV document from a string - $writer = new XLSXWriter(); + $writer = new XLSXWriter(); $sheetName = !empty($model->sheetName) ? $model->sheetName : 'Sheet'; if (!empty($header)) { @@ -155,17 +152,17 @@ public function downloadHash($fileHash = null): array | bool */ private function writeAndRedirect(string $content, string $filename, string $mimeType): void { - $tempPath = Craft::$app->path->getTempPath() . DIRECTORY_SEPARATOR . 'beam' . DIRECTORY_SEPARATOR; + $tempPath = Craft::$app->path->getTempPath() . DIRECTORY_SEPARATOR . 'beam' . DIRECTORY_SEPARATOR; $tempFilename = StringHelper::randomString(12) . "-{$filename}"; - $config = [ - 'filename' => $filename, + $config = [ + 'filename' => $filename, 'tempFilename' => $tempFilename, - 'mimeType' => $mimeType, + 'mimeType' => $mimeType, ]; $hashConfig = $this->hashConfig($config); $verifyHash = Craft::$app->getSecurity()->hashData($hashConfig); - $url = UrlHelper::siteUrl('beam/download', [ + $url = UrlHelper::siteUrl('beam/download', [ 'hash' => $verifyHash, ]); @@ -188,18 +185,19 @@ public function unhashConfig(string $hash): array $config = base64_decode($hash); $config = explode('||', $config); - list ($filename, $tempFilename, $mimeType) = $config; + list($filename, $tempFilename, $mimeType) = $config; $config = [ - 'filename' => $filename, + 'filename' => $filename, 'tempFilename' => $tempFilename, - 'mimeType' => $mimeType, + 'mimeType' => $mimeType, ]; return $config; } - private function normalizeCellFormat(string $type): string { + private function normalizeCellFormat(string $type): string + { $types = [ 'number' => 'integer', 'date' => 'date', diff --git a/src/variables/BeamVariable.php b/src/variables/BeamVariable.php index f42e137..cfb2189 100644 --- a/src/variables/BeamVariable.php +++ b/src/variables/BeamVariable.php @@ -12,8 +12,6 @@ use superbig\beam\Beam; -use Craft; - /** * @author Superbig * @package Beam @@ -29,7 +27,7 @@ class BeamVariable * * @return null */ - public function create ($options = []) + public function create($options = []) { return Beam::$plugin->beamService->create($options); }