Skip to content

Commit 7be0fb7

Browse files
author
Mario Blazek
committed
Removed hardcoded values
1 parent 09dbb0a commit 7be0fb7

File tree

2 files changed

+37
-5
lines changed

2 files changed

+37
-5
lines changed

bundle/Constants.php

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Netgen\Bundle\InformationCollectionBundle;
4+
5+
class Constants
6+
{
7+
/**
8+
* Recipient field identifier
9+
*/
10+
const FIELD_RECIPIENT = 'recipient';
11+
12+
/**
13+
* Sender field identifier
14+
*/
15+
const FIELD_SENDER = 'sender';
16+
17+
/**
18+
* Subject field identifier
19+
*/
20+
const FIELD_SUBJECT = 'subject';
21+
22+
/**
23+
* Email field type
24+
*/
25+
const FIELD_TYPE_EMAIL = 'email';
26+
27+
/**
28+
* Text field type
29+
*/
30+
const FIELD_TYPE_TEXT = 'text';
31+
}

bundle/Factory/EmailDataFactory.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use eZ\Publish\Core\Helper\TranslationHelper;
88
use eZ\Publish\API\Repository\Values\Content\Content;
99
use Netgen\Bundle\InformationCollectionBundle\Value\EmailData;
10+
use Netgen\Bundle\InformationCollectionBundle\Constants;
1011

1112
class EmailDataFactory
1213
{
@@ -61,9 +62,9 @@ public function __construct(
6162
public function build(Content $content)
6263
{
6364
return new EmailData(
64-
$this->resolve($content, 'recipient', 'email'),
65-
$this->resolve($content, 'sender', 'email'),
66-
$this->resolve($content, 'subject'),
65+
$this->resolve($content, Constants::FIELD_RECIPIENT, Constants::FIELD_TYPE_EMAIL),
66+
$this->resolve($content, Constants::FIELD_SENDER, Constants::FIELD_TYPE_EMAIL),
67+
$this->resolve($content, Constants::FIELD_SUBJECT),
6768
$this->resolveTemplate($content)
6869
);
6970
}
@@ -75,9 +76,9 @@ public function build(Content $content)
7576
* @param string $field
7677
* @param string $property
7778
*
78-
* @return mixed
79+
* @return string
7980
*/
80-
protected function resolve(Content $content, $field, $property = 'text')
81+
protected function resolve(Content $content, $field, $property = Constants::FIELD_TYPE_TEXT)
8182
{
8283
if (array_key_exists($field, $content->fields) &&
8384
!$this->fieldHelper->isFieldEmpty($content, $field)

0 commit comments

Comments
 (0)