Skip to content

Commit fbcf640

Browse files
committed
Add return types
1 parent f6be85f commit fbcf640

File tree

12 files changed

+65
-56
lines changed

12 files changed

+65
-56
lines changed

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/Card.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,14 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

14+
use Symfony\Component\Notifier\Bridge\GoogleChat\GoogleChatOptions;
15+
1416
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards
18+
*
19+
* @method GoogleChatOptions end()
1620
*
17-
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
21+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1822
*/
1923
final class Card implements ComponentInterface
2024
{
@@ -28,10 +32,9 @@ public function __construct(array $header = [], array $sections = [])
2832
}
2933

3034
/**
31-
* @param string $subtitle
3235
* @param string $imageStyle square ("IMAGE") or circular ("AVATAR")
3336
*/
34-
public function header(string $title, string $subtitle = null, string $imageUrl = null, string $imageStyle = null)
37+
public function header(string $title, string $subtitle = null, string $imageUrl = null, string $imageStyle = null): self
3538
{
3639
$this->options['header'] = array_filter([
3740
'title' => $title,
@@ -43,10 +46,7 @@ public function header(string $title, string $subtitle = null, string $imageUrl
4346
return $this;
4447
}
4548

46-
/**
47-
* @return Section
48-
*/
49-
public function section(string $header = null)
49+
public function section(string $header = null): Section
5050
{
5151
$section = new Section($header);
5252
$section->setEndCallback([$this, 'addSection']);
@@ -59,7 +59,7 @@ public function section(string $header = null)
5959
/**
6060
* @return $this
6161
*/
62-
public function addSection(Section $section)
62+
public function addSection(Section $section): self
6363
{
6464
$this->assertNotDirty($section);
6565

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/ComponentTrait.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,21 @@
1515

1616
/**
1717
* @author Jérôme Tamarelle <jerome@tamarelle.net>
18+
*
19+
* @internal
1820
*/
1921
trait ComponentTrait
2022
{
2123
protected $options = [];
22-
protected $dirty = null;
24+
25+
/**
26+
* @var ComponentInterface|null
27+
*/
28+
protected $dirty;
29+
30+
/**
31+
* @var callable|null Called by end() method
32+
*/
2333
private $endCallback;
2434

2535
public function toArray(): array
@@ -39,7 +49,7 @@ public function end()
3949
throw new \LogicException('Cannot call "end()" on a component.');
4050
}
4151

42-
// Remove circular reference
52+
// Removes circular reference
4353
$this->endCallback = null;
4454

4555
return $endCallback($this);
@@ -53,6 +63,9 @@ public function setEndCallback(callable $endCallback)
5363
$this->endCallback = $endCallback;
5464
}
5565

66+
/**
67+
* @throws NotEndedComponentException
68+
*/
5669
private function assertNotDirty(ComponentInterface $component)
5770
{
5871
if (null !== $this->dirty && $component !== $this->dirty) {

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/ImageButton.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16-
*
1715
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
16+
*
17+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1818
*/
1919
final class ImageButton implements ComponentInterface
2020
{
@@ -24,7 +24,7 @@ public function __construct(string $icon, string $link)
2424
{
2525
$this->options = [
2626
'imageButton' => [
27-
('http' === substr($icon, 0, 4) ? 'iconUrl' : 'icon') => $icon,
27+
(0 === strpos($icon, 'http') ? 'iconUrl' : 'icon') => $icon,
2828
'onClick' => [
2929
'openLink' => [
3030
'url' => $link,

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/ImageWidget.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16-
*
1715
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#image_widget
16+
*
17+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1818
*/
1919
final class ImageWidget implements WidgetInterface
2020
{
@@ -33,7 +33,7 @@ public function __construct(string $imageUrl, string $link = null)
3333
}
3434
}
3535

36-
public function link(string $link)
36+
public function link(string $link): self
3737
{
3838
$this->options['image']['onClick'] = [
3939
'openLink' => [

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/KeyValueWidget.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16-
*
1715
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#keyvalue
16+
*
17+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1818
*/
1919
final class KeyValueWidget implements WidgetInterface
2020
{
@@ -25,14 +25,14 @@ public function __construct()
2525
$this->options = ['keyValue' => []];
2626
}
2727

28-
public function topLabel(string $topLabel)
28+
public function topLabel(string $topLabel): self
2929
{
3030
$this->options['keyValue']['topLabel'] = $topLabel;
3131

3232
return $this;
3333
}
3434

35-
public function content(string $content, bool $multiline = false)
35+
public function content(string $content, bool $multiline = false): self
3636
{
3737
$this->options['keyValue']['content'] = $content;
3838

@@ -43,35 +43,35 @@ public function content(string $content, bool $multiline = false)
4343
return $this;
4444
}
4545

46-
public function bottomLabel(string $bottomLabel)
46+
public function bottomLabel(string $bottomLabel): self
4747
{
4848
$this->options['keyValue']['bottomLabel'] = $bottomLabel;
4949

5050
return $this;
5151
}
5252

53-
public function link(string $link)
53+
public function link(string $link): self
5454
{
5555
$this->options['keyValue']['onClick'] = ['openLink' => ['url' => $link]];
5656

5757
return $this;
5858
}
5959

60-
public function icon(string $icon)
60+
public function icon(string $icon): self
6161
{
6262
$this->options['keyValue']['http' === substr($icon, 0, 4) ? 'iconUrl' : 'icon'] = $icon;
6363

6464
return $this;
6565
}
6666

67-
public function imageButton(string $icon, string $link)
67+
public function imageButton(string $icon, string $link): self
6868
{
6969
$this->options['keyValue']['button'] = (new ImageButton($icon, $link))->toArray();
7070

7171
return $this;
7272
}
7373

74-
public function textButton(string $text, string $link)
74+
public function textButton(string $text, string $link): self
7575
{
7676
$this->options['keyValue']['button'] = (new TextButton($text, $link))->toArray();
7777

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/Section.php

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16-
*
17-
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
15+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#sections_widgets
1816
*
1917
* @method Card end()
18+
*
19+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
2020
*/
21-
final class Section implements WidgetInterface
21+
final class Section implements ComponentInterface
2222
{
2323
use ComponentTrait;
2424

@@ -30,38 +30,35 @@ public function __construct(string $header = null)
3030
$this->options['widgets'] = [];
3131
}
3232

33-
public function image(string $imageUrl, string $link = null)
33+
public function image(string $imageUrl, string $link = null): self
3434
{
3535
$this->addWidget(new ImageWidget($imageUrl, $link));
3636

3737
return $this;
3838
}
3939

40-
public function textParagraph(string $text)
40+
public function textParagraph(string $text): self
4141
{
4242
$this->addWidget(new TextParagraphWidget($text));
4343

4444
return $this;
4545
}
4646

47-
public function textButton(string $text, string $link)
47+
public function textButton(string $text, string $link): self
4848
{
4949
$this->addWidget((new ButtonsWidget())->textButton($text, $link));
5050

5151
return $this;
5252
}
5353

54-
public function imageButton(string $imageUrl, string $link)
54+
public function imageButton(string $imageUrl, string $link): self
5555
{
5656
$this->addWidget((new ButtonsWidget())->imageButton($imageUrl, $link));
5757

5858
return $this;
5959
}
6060

61-
/**
62-
* @return ButtonsWidget
63-
*/
64-
public function buttons()
61+
public function buttons(): ButtonsWidget
6562
{
6663
$widget = new ButtonsWidget();
6764
$this->assertNotDirty($widget);
@@ -71,14 +68,14 @@ public function buttons()
7168
return $widget;
7269
}
7370

74-
public function keyValue(string $topLabel, string $content)
71+
public function keyValue(string $topLabel, string $content): self
7572
{
7673
$this->addWidget((new KeyValueWidget())->topLabel($topLabel)->content($content));
7774

7875
return $this;
7976
}
8077

81-
public function addWidget(WidgetInterface $widget)
78+
public function addWidget(WidgetInterface $widget): self
8279
{
8380
$this->assertNotDirty($widget);
8481

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/TextButton.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16-
*
1715
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#buttons
16+
*
17+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1818
*/
1919
final class TextButton implements ComponentInterface
2020
{

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/TextParagraphWidget.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
16-
*
1715
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#textparagraph
16+
*
17+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1818
*/
1919
final class TextParagraphWidget implements WidgetInterface
2020
{

src/Symfony/Component/Notifier/Bridge/GoogleChat/Component/WidgetInterface.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,12 @@
1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Component;
1313

1414
/**
15-
* @author Jérôme Tamarelle <jerome@tamarelle.net>
15+
* Identify Widget components.
16+
*
17+
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#sections_widgets
1618
*
17-
* @see https://developers.google.com/hangouts/chat/reference/message-formats/cards#image_widget
19+
* @author Jérôme Tamarelle <jerome@tamarelle.net>
1820
*/
1921
interface WidgetInterface extends ComponentInterface
2022
{
21-
public function toArray(): array;
2223
}

src/Symfony/Component/Notifier/Bridge/GoogleChat/Exception/NotEndedComponentException.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace Symfony\Component\Notifier\Bridge\GoogleChat\Exception;
1313

14-
class NotEndedComponentException extends \LogicException
14+
use Symfony\Component\Notifier\Exception\LogicException;
15+
16+
class NotEndedComponentException extends LogicException
1517
{
1618
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy