Skip to content

Commit

Permalink
Migrate to SF 3
Browse files Browse the repository at this point in the history
  • Loading branch information
PedroTroller committed Sep 27, 2017
1 parent 5867769 commit 2763e3f
Show file tree
Hide file tree
Showing 32 changed files with 194 additions and 273 deletions.
22 changes: 0 additions & 22 deletions .php_cs

This file was deleted.

30 changes: 30 additions & 0 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

$finder = PhpCsFixer\Finder::create();

$finder->in(__DIR__);
$finder->exclude('vendor');

$config = PhpCsFixer\Config::create()
->setRiskyAllowed(true)
->setRules([
'@Symfony' => true,
'@Symfony:risky' => true,
'PedroTroller/line_break_between_statements' => true,
'PedroTroller/phpspec' => true,
'PedroTroller/single_line_comment' => ['action' => 'expanded'],
'array_syntax' => [ 'syntax' => 'short', ],
'binary_operator_spaces' => [ 'align_double_arrow' => true, 'align_equals' => true, ],
'blank_line_before_statement' => true,
'ordered_class_elements' => true,
'ordered_imports' => true,
'phpdoc_types_order' => true,
'semicolon_after_instruction' => true,
'single_line_comment_style' => true,
])
->setUsingCache(false)
->registerCustomFixers(new PedroTroller\CS\Fixer\Fixers())
->setFinder($finder)
;

return $config;
29 changes: 16 additions & 13 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,33 @@
}
],
"require": {
"php": ">=7.1",
"doctrine/collections": "~1.0",
"swiftmailer/swiftmailer": "~5.0",
"symfony/config": "~2.4",
"symfony/dependency-injection": "~2.4",
"symfony/framework-bundle": "~2.4",
"symfony/http-kernel": "~2.4",
"symfony/security-bundle": "~2.0",
"symfony/twig-bundle": "~2.4"
"swiftmailer/swiftmailer": "~6.0",
"symfony/config": "~3.0",
"symfony/dependency-injection": "~3.0",
"symfony/expression-language": "~3.0",
"symfony/framework-bundle": "~3.0",
"symfony/http-kernel": "~3.0",
"symfony/property-access": "~3.0",
"symfony/twig-bundle": "~3.0"
},
"require-dev": {
"knplabs/phpspec-welldone-extension": "~1.0",
"phpspec/phpspec": "^2.3"
"pedrotroller/php-cs-custom-fixer": "~2.0@dev",
"phpspec/phpspec": "^4.0",
"phpstan/phpstan": "^0.8.5"
},
"autoload": {
"psr-0": {
"Knp\\UniMail": "src/"
"psr-4": {
"Knp\\UniMail\\": "src/Knp/UniMail"
}
},
"config": {
"bin-dir": "bin"
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.0.x-dev"
"dev-master": "2.0.x-dev"
}
}
}
2 changes: 0 additions & 2 deletions phpspec.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace spec\Knp\Rad\Mailer\AttachmentFactory;
namespace spec\Knp\UniMail\AttachmentFactory;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class LocalAttachmentFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\AttachmentFactory\LocalAttachmentFactory');
$this->shouldHaveType('Knp\UniMail\AttachmentFactory\LocalAttachmentFactory');
}

function it_supports_existing_files()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

namespace spec\Knp\Rad\Mailer\AttachmentFactory;
namespace spec\Knp\UniMail\AttachmentFactory;

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class RemoteAttachmentFactorySpec extends ObjectBehavior
{
function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\AttachmentFactory\RemoteAttachmentFactory');
$this->shouldHaveType('Knp\UniMail\AttachmentFactory\RemoteAttachmentFactory');
}

function it_supports_existing_urls()
Expand Down
11 changes: 5 additions & 6 deletions spec/Knp/UniMail/MailFactory/ConfigurationAwareFactorySpec.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
<?php

namespace spec\Knp\Rad\Mailer\MailFactory;
namespace spec\Knp\UniMail\MailFactory;

use Knp\Rad\Mailer\Mail;
use Knp\Rad\Mailer\MailFactory;
use Knp\UniMail\Mail;
use Knp\UniMail\MailFactory;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

class ConfigurationAwareFactorySpec extends ObjectBehavior
{
Expand All @@ -15,15 +14,15 @@ function let(MailFactory $factory)
'the_mail' => [
'from' => '[email protected]',
'to' => '[email protected]',
]
],
];

$this->beConstructedWith($configuration, $factory);
}

function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\MailFactory\ConfigurationAwareFactory');
$this->shouldHaveType('Knp\UniMail\MailFactory\ConfigurationAwareFactory');
}

function it_instantiate_a_new_mail_with_configuration($factory, Mail $mail)
Expand Down
20 changes: 10 additions & 10 deletions spec/Knp/UniMail/Mailer/EventDispatcherMailerSpec.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
<?php

namespace spec\Knp\Rad\Mailer\Mailer;
namespace spec\Knp\UniMail\Mailer;

use Knp\Rad\Mailer\Mail;
use Knp\Rad\Mailer\Mail\SwiftMail;
use Knp\Rad\Mailer\Mailer;
use Knp\Rad\Mailer\MailerEvents;
use Knp\UniMail\Mail;
use Knp\UniMail\Mail\SwiftMail;
use Knp\UniMail\Mailer;
use Knp\UniMail\MailerEvents;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
Expand All @@ -19,7 +19,7 @@ function let(Mailer $wrapped, EventDispatcherInterface $dispatcher)

function it_is_initializable()
{
$this->shouldHaveType('Knp\Rad\Mailer\Mailer\EventDispatcherMailer');
$this->shouldHaveType('Knp\UniMail\Mailer\EventDispatcherMailer');
}

function it_ask_to_wrapped_mailer_to_create_a_mail($wrapped, Mail $mail)
Expand All @@ -43,7 +43,7 @@ function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher)
$dispatcher
->dispatch(
MailerEvents::PRE_SEND,
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
Expand All @@ -53,7 +53,7 @@ function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher)
$dispatcher
->dispatch(
MailerEvents::preSend($mail),
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
Expand All @@ -63,7 +63,7 @@ function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher)
$dispatcher
->dispatch(
MailerEvents::POST_SEND,
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
Expand All @@ -73,7 +73,7 @@ function it_dispatchs_events_when_a_mail_is_sent($wrapped, $dispatcher)
$dispatcher
->dispatch(
MailerEvents::postSend($mail),
Argument::that(function($e) use ($mail) {
Argument::that(function ($e) use ($mail) {
return $mail === $e->getMail();
})
)
Expand Down
13 changes: 5 additions & 8 deletions src/Knp/UniMail/AttachmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

namespace Knp\UniMail;

use Swift_Mime_Attachment;

interface AttachmentFactory
{
/**
* @param mixed $content
*
* @return bool
*/
public function supports($content);
public function supports($content): bool;

/**
* @param string $name
* @param mixed $content
*
* @return Swift_Attachment
* @param mixed $content
*/
public function createAttachment($name, $content);
public function createAttachment(string $name, $content): Swift_Mime_Attachment;
}
12 changes: 9 additions & 3 deletions src/Knp/UniMail/AttachmentFactory/ChainAttachmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Knp\UniMail\AttachmentFactory;

use Exception;
use Knp\UniMail\AttachmentFactory;
use Swift_Mime_Attachment;

class ChainAttachmentFactory implements AttachmentFactory
{
Expand All @@ -18,10 +20,11 @@ public function __construct(array $factories)
{
$this->factories = $factories;
}

/**
* {@inheritdoc}
*/
public function supports($content)
public function supports($content): bool
{
foreach ($this->factories as $factory) {
if (true === $factory->supports($content)) {
Expand All @@ -35,7 +38,7 @@ public function supports($content)
/**
* {@inheritdoc}
*/
public function createAttachment($name, $content)
public function createAttachment(string $name, $content): Swift_Mime_Attachment
{
foreach ($this->factories as $factory) {
if (true === $factory->supports($content)) {
Expand All @@ -48,15 +51,18 @@ public function createAttachment($name, $content)
switch (true) {
case is_array($content):
$message = sprintf($message, 'an', 'array');

break;
case is_object($content):
$message = sprintf($message, 'object', get_class($content));

break;
default:
$message = sprintf($message, gettype($content), $content);

break;
}

throw new \Exception($message);
throw new Exception($message);
}
}
7 changes: 4 additions & 3 deletions src/Knp/UniMail/AttachmentFactory/LocalAttachmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Knp\UniMail\AttachmentFactory;
use Swift_Attachment;
use Swift_Mime_Attachment;

class LocalAttachmentFactory implements AttachmentFactory
{
/**
* {@inheritdoc}
*/
public function supports($content)
public function supports($content): bool
{
if (false === is_string($content)) {
return false;
Expand All @@ -22,11 +23,11 @@ public function supports($content)
/**
* {@inheritdoc}
*/
public function createAttachment($name, $content)
public function createAttachment(string $name, $content): Swift_Mime_Attachment
{
$attachment = Swift_Attachment::fromPath($content);

if (true === is_string($name)) {
if (is_string($name)) {
$attachment->setFilename($name);
}

Expand Down
5 changes: 3 additions & 2 deletions src/Knp/UniMail/AttachmentFactory/RemoteAttachmentFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@

use Knp\UniMail\AttachmentFactory;
use Swift_Attachment;
use Swift_Mime_Attachment;

class RemoteAttachmentFactory implements AttachmentFactory
{
/**
* {@inheritdoc}
*/
public function supports($content)
public function supports($content): bool
{
if (false === is_string($content)) {
return false;
Expand All @@ -28,7 +29,7 @@ public function supports($content)
/**
* {@inheritdoc}
*/
public function createAttachment($name, $content)
public function createAttachment(string $name, $content): Swift_Mime_Attachment
{
$attachment = Swift_Attachment::fromPath($content);

Expand Down
9 changes: 2 additions & 7 deletions src/Knp/UniMail/Cid/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,15 @@ public function all()

/**
* @param Swift_Mime_Attachment $cid
*
* @return Collection
*/
public function add(Swift_Mime_Attachment $cid)
public function add(Swift_Mime_Attachment $cid): Collection
{
$this->cids[$cid->getId()] = $cid;

return $this;
}

/**
* @return Collection
*/
public function clear()
public function clear(): Collection
{
$this->cids = [];

Expand Down
Loading

0 comments on commit 2763e3f

Please sign in to comment.