Skip to content
This repository has been archived by the owner on Mar 7, 2024. It is now read-only.

Commit

Permalink
code style
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Gerig committed May 29, 2019
1 parent 06dd5c0 commit 609ad62
Show file tree
Hide file tree
Showing 10 changed files with 77 additions and 39 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
]
}
}
}
}
12 changes: 7 additions & 5 deletions src/Configuration/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

namespace WvisionBundle\Configuration;

use Exception;
use Pimcore;
use Pimcore\Extension\Bundle\PimcoreBundleManager;
use Symfony\Component\EventDispatcher\GenericEvent;

Expand Down Expand Up @@ -43,7 +45,7 @@ public function __construct(PimcoreBundleManager $bundleManager)
/**
* @param array $config
*/
public function setConfig(array $config = [])
public function setConfig(array $config = []): void
{
$this->config = $config;
}
Expand Down Expand Up @@ -86,7 +88,7 @@ public function getLocalizedPath($slot, $locale = null)
'route' => $data
]);

\Pimcore::getEventDispatcher()->dispatch('wvision.path.route', $event);
Pimcore::getEventDispatcher()->dispatch('wvision.path.route', $event);

if ($event->hasArgument('url')) {
$url = $event->getArgument('url');
Expand All @@ -105,7 +107,7 @@ public function getLocalizedPath($slot, $locale = null)
/**
* @param array $config
*/
public function setSystemConfig(array $config = [])
public function setSystemConfig(array $config = []): void
{
$this->systemConfig = $config;
}
Expand All @@ -127,10 +129,10 @@ public function hasBundle($bundleName = 'ExtensionBundle\ExtensionBundle'): bool
{
try {
$hasExtension = $this->bundleManager->isEnabled($bundleName);
} catch (\Exception $e) {
} catch (Exception $e) {
$hasExtension = false;
}

return $hasExtension;
}
}
}
5 changes: 3 additions & 2 deletions src/DependencyInjection/WvisionExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace WvisionBundle\DependencyInjection;

use Exception;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Extension\Extension;
Expand All @@ -22,9 +23,9 @@ final class WvisionExtension extends Extension
/**
* @param array $configs
* @param ContainerBuilder $container
* @throws \Exception
* @throws Exception
*/
public function load(array $configs, ContainerBuilder $container)
public function load(array $configs, ContainerBuilder $container): void
{
$configuration = new Configuration();
$this->processConfiguration($configuration, $configs);
Expand Down
2 changes: 1 addition & 1 deletion src/Installer/AssetsInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function __construct(KernelInterface $kernel, Filesystem $fileSystem)
/**
* {@inheritdoc}
*/
public function installAssets()
public function installAssets(): void
{
$installSourcesPath = $this->kernel->locateResource('@WvisionBundle/Resources/install');

Expand Down
10 changes: 5 additions & 5 deletions src/Installer/BundleInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ final class BundleInstaller extends MigrationInstaller
/**
* @param AssetsInstaller $assetsInstaller
*/
public function setAssetsInstaller(AssetsInstaller $assetsInstaller)
public function setAssetsInstaller(AssetsInstaller $assetsInstaller): void
{
$this->assetsInstaller = $assetsInstaller;
}

/**
* @param DemoInstaller $demoInstaller
*/
public function setDemoInstaller(DemoInstaller $demoInstaller)
public function setDemoInstaller(DemoInstaller $demoInstaller): void
{
$this->demoInstaller = $demoInstaller;
}
Expand All @@ -57,15 +57,15 @@ protected function beforeInstallMigration()
* @param Schema $schema
* @param Version $version
*/
public function migrateInstall(Schema $schema, Version $version)
public function migrateInstall(Schema $schema, Version $version): void
{
}

/**
* @param Schema $schema
* @param Version $version
*/
public function migrateUninstall(Schema $schema, Version $version)
public function migrateUninstall(Schema $schema, Version $version): void
{
}
}
}
4 changes: 3 additions & 1 deletion src/Installer/DemoInstaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
namespace WvisionBundle\Installer;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;

final class DemoInstaller
{
Expand All @@ -31,8 +32,9 @@ public function __construct(Connection $db)

/**
* {@inheritdoc}
* @throws DBALException
*/
public function installDemo()
public function installDemo(): void
{
$columns = $this->db->getSchemaManager()->listTableColumns('documents');
$hasVersionCount = false;
Expand Down
33 changes: 26 additions & 7 deletions src/Tool/Ics.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@

namespace WvisionBundle\Tool;

use DateTime;
use Exception;

class Ics
{
/**
* The default date and time format.
*/
const DT_FORMAT = 'Ymd\THis\Z';
private const DT_FORMAT = 'Ymd\THis\Z';

/**
* @var array Available properties.
Expand All @@ -40,8 +43,10 @@ class Ics
* Receives all data.
*
* @param $props
*
* @throws Exception
*/
public function setProps($props)
public function setProps($props): void
{
$this->set($props);
}
Expand All @@ -51,14 +56,16 @@ public function setProps($props)
*
* @param $key
* @param bool $val
*
* @throws Exception
*/
public function set($key, $val = false)
public function set($key, $val = false): void
{
if (\is_array($key)) {
if (is_array($key)) {
foreach ($key as $k => $v) {
$this->set($k, $v);
}
} else if (\in_array($key, self::$availableProperties, true)) {
} else if (in_array($key, self::$availableProperties, true)) {
$this->properties[$key] = $this->sanitizeVal($val, $key);
}
}
Expand All @@ -67,6 +74,8 @@ public function set($key, $val = false)
* Converts all properties to a ICS-file.
*
* @return string The ICS-file
*
* @throws Exception
*/
public function toString(): string
{
Expand All @@ -79,6 +88,8 @@ public function toString(): string
* Composes all properties together.
*
* @return array
*
* @throws Exception
*/
private function buildProps(): array
{
Expand Down Expand Up @@ -117,7 +128,10 @@ private function buildProps(): array
*
* @param $val
* @param bool $key
*
* @return mixed|string
*
* @throws Exception
*/
private function sanitizeVal($val, $key = false)
{
Expand All @@ -129,6 +143,7 @@ private function sanitizeVal($val, $key = false)
break;
default:
$val = $this->escapeString($val);
break;
}

return $val;
Expand All @@ -138,11 +153,14 @@ private function sanitizeVal($val, $key = false)
* Formats a timestamp with the given setting.
*
* @param $timestamp
*
* @return string
*
* @throws Exception
*/
private function formatTimestamp($timestamp): string
{
$dt = new \DateTime($timestamp);
$dt = new DateTime($timestamp);

return $dt->format(self::DT_FORMAT);
}
Expand All @@ -151,10 +169,11 @@ private function formatTimestamp($timestamp): string
* Escapes all string.
*
* @param $str
*
* @return null|string|string[]
*/
private function escapeString($str)
{
return preg_replace('/([\,;])/','\\\$1', $str);
}
}
}
26 changes: 16 additions & 10 deletions src/Tool/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

namespace WvisionBundle\Tool;

use Exception;
use Pimcore\Mail;
use Pimcore\Model\Asset;
use Pimcore\Model\Document;
Expand Down Expand Up @@ -63,9 +64,9 @@ public function getEmails(): array
/**
* @param array|string $emails
*/
public function setEmails($emails)
public function setEmails($emails): void
{
if (\is_string($emails)) {
if (is_string($emails)) {
$this->emails[] = $emails;
} else {
$this->emails = $emails;
Expand All @@ -83,7 +84,7 @@ public function getDocuments(): array
/**
* @param array|Document $documents
*/
public function setDocuments($documents)
public function setDocuments($documents): void
{
if ($documents instanceof Document\Email) {
$this->documents[] = $documents;
Expand All @@ -103,7 +104,7 @@ public function getAssets(): array
/**
* @param array|Asset $assets
*/
public function setAssets($assets)
public function setAssets($assets): void
{
if ($assets instanceof Asset) {
$this->assets[] = $assets;
Expand All @@ -123,16 +124,18 @@ public function isSuccess(): bool
/**
* @param bool $success
*/
public function setSuccess($success)
public function setSuccess($success): void
{
$this->success = $success;
}

/**
* @param $data
* @param array $adminEmail
*
* @return bool
* @throws \Exception
*
* @throws Exception
*/
public function sendEmails($data, array $adminEmail = []): bool
{
Expand Down Expand Up @@ -174,14 +177,15 @@ public function sendEmails($data, array $adminEmail = []): bool
/**
* @param $data
* @param $admin
*
* @return array
*/
public function parseData($data, $admin): array
{
$document = $this->documentResolver->getDocument();

foreach ($data as $param) {
if (\is_string($param) && Mail::isValidEmailAddress($param)) {
if (is_string($param) && Mail::isValidEmailAddress($param)) {
$this->setEmails($param);
}
else if ($param instanceof Document\Email) {
Expand All @@ -202,7 +206,7 @@ public function parseData($data, $admin): array
$i = 0;
foreach ($admin as $param) {
$adminArray['emails'] = [];
if (\is_string($param) && Mail::isValidEmailAddress($param)) {
if (is_string($param) && Mail::isValidEmailAddress($param)) {
$adminArray['emails'][$i] = $param;
}

Expand Down Expand Up @@ -237,8 +241,10 @@ public function parseData($data, $admin): array
* @param $params
* @param Document\Email $document
* @param array $assets
*
* @return bool
* @throws \Exception
*
* @throws Exception
*/
public function send($emails, array $params, Document\Email $document, array $assets): bool
{
Expand All @@ -257,4 +263,4 @@ public function send($emails, array $params, Document\Email $document, array $as

return $sentEmail instanceof Mail;
}
}
}
10 changes: 7 additions & 3 deletions src/Twig/Extension/ObfuscateEmailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

namespace WvisionBundle\Twig\Extension;

class ObfuscateEmailExtension extends \Twig_Extension
use Twig\Extension\AbstractExtension;
use Twig\TwigFilter;

class ObfuscateEmailExtension extends AbstractExtension
{
/**
* Returns a list of filters to add to the existing list.
Expand All @@ -22,7 +25,7 @@ class ObfuscateEmailExtension extends \Twig_Extension
public function getFilters(): array
{
return [
new \Twig_Filter(
new TwigFilter(
'obfuscateEmail', [$this, 'parse'], [
'is_safe' => ['html']
]
Expand All @@ -34,10 +37,11 @@ public function getFilters(): array
* Twig filter callback
*
* @param $email
*
* @return string
*/
public function parse($email): string
{
return mb_encode_numericentity($email, [0, 0xffff, 0, 0xffff], 'utf-8');
}
}
}
Loading

0 comments on commit 609ad62

Please sign in to comment.