Skip to content

Commit ba62684

Browse files
Merge pull request #127 from laravelwebdev/add-docstrings-2
Add docstrings to helper methods
2 parents 4416e5f + d4d8201 commit ba62684

File tree

3 files changed

+91
-1
lines changed

3 files changed

+91
-1
lines changed

app/Helpers/Inspiring.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1401,6 +1401,11 @@ class Inspiring
14011401
],
14021402
];
14031403

1404+
/**
1405+
* Show a random quote from the list of quotes.
1406+
*
1407+
* @return array
1408+
*/
14041409
public static function show()
14051410
{
14061411
$data['topic'] = Arr::random(array_keys(static::$quotes));

app/Helpers/Policy.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,58 +16,119 @@ public static function make()
1616
return new static;
1717
}
1818

19+
/**
20+
* Check if the user has access based on roles.
21+
*
22+
* @param array $roles
23+
* @return bool
24+
*/
1925
private static function hasAccess($roles): bool
2026
{
2127
return ! empty(array_intersect($roles, session('role')));
2228
}
2329

30+
/**
31+
* Get the current access status.
32+
*
33+
* @return bool
34+
*/
2435
public function get(): bool
2536
{
2637
return $this->allowed;
2738
}
2839

40+
/**
41+
* Set access allowed for specific roles.
42+
*
43+
* @param string $roles
44+
* @return self
45+
*/
2946
public function allowedFor(string $roles = 'all'): self
3047
{
3148
$this->allowed = $roles === 'all' || self::hasAccess(explode(',', $roles), session('role'));
3249

3350
return $this;
3451
}
3552

53+
/**
54+
* Set access not allowed for specific roles.
55+
*
56+
* @param string $roles
57+
* @return self
58+
*/
3659
public function notAllowedFor(string $roles = 'all'): self
3760
{
3861
$this->allowed = $roles !== 'all' && self::hasAccess(array_diff(array_keys(Helper::ROLE), explode(',', $roles)), session('role'));
3962

4063
return $this;
4164
}
4265

66+
/**
67+
* Set access allowed for a specific year.
68+
*
69+
* @param mixed $year
70+
* @return self
71+
*/
4372
public function withYear($year): self
4473
{
4574
$this->allowed = $this->allowed && (session('year') == $year);
4675

4776
return $this;
4877
}
4978

79+
/**
80+
* Set access allowed if two expressions are equal.
81+
*
82+
* @param mixed $expr1
83+
* @param mixed $expr2
84+
* @param bool $strict
85+
* @return self
86+
*/
5087
public function andEqual($expr1, $expr2, $strict = true): self
5188
{
5289
$this->allowed = $this->allowed && ($strict ? $expr1 === $expr2 : $expr1 == $expr2);
5390

5491
return $this;
5592
}
5693

94+
/**
95+
* Set access allowed if two expressions are not equal.
96+
*
97+
* @param mixed $expr1
98+
* @param mixed $expr2
99+
* @param bool $strict
100+
* @return self
101+
*/
57102
public function andNotEqual($expr1, $expr2, $strict = true): self
58103
{
59104
$this->allowed = $this->allowed && ($strict ? $expr1 !== $expr2 : $expr1 != $expr2);
60105

61106
return $this;
62107
}
63108

109+
/**
110+
* Set access allowed if either of two expressions are equal.
111+
*
112+
* @param mixed $expr1
113+
* @param mixed $expr2
114+
* @param bool $strict
115+
* @return self
116+
*/
64117
public function orEqual($expr1, $expr2, $strict = true): self
65118
{
66119
$this->allowed = $this->allowed || ($strict ? $expr1 === $expr2 : $expr1 == $expr2);
67120

68121
return $this;
69122
}
70123

124+
/**
125+
* Set access allowed if either of two expressions are not equal.
126+
*
127+
* @param mixed $expr1
128+
* @param mixed $expr2
129+
* @param bool $strict
130+
* @return self
131+
*/
71132
public function orNotEqual($expr1, $expr2, $strict = true): self
72133
{
73134
$this->allowed = $this->allowed || ($strict ? $expr1 !== $expr2 : $expr1 != $expr2);

app/Helpers/TemplateProcessor.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,45 @@
77

88
class TemplateProcessor extends PhpWordTemplateProcessor
99
{
10+
/**
11+
* Get the main part of the temporary document.
12+
*
13+
* @return string
14+
*/
1015
public function gettempDocumentMainPart()
1116
{
1217
return $this->tempDocumentMainPart;
1318
}
1419

20+
/**
21+
* Set the main part of the temporary document.
22+
*
23+
* @param string $new
24+
* @return void
25+
*/
1526
public function settempDocumentMainPart($new)
1627
{
17-
return $this->tempDocumentMainPart = $new;
28+
$this->tempDocumentMainPart = $new;
1829
}
1930

31+
/**
32+
* Ensure the subject is UTF-8 encoded.
33+
*
34+
* @param string $subject
35+
* @return string
36+
*/
2037
protected static function ensureUtf8Encoded($subject)
2138
{
2239
return ($subject !== null) ? Text::toUTF8($subject) : '';
2340
}
2441

42+
/**
43+
* Clone a row in the document.
44+
*
45+
* @param string $search
46+
* @param int $numberOfClones
47+
* @return void
48+
*/
2549
public function cloneRow($search, $numberOfClones): void
2650
{
2751
$search = static::ensureMacroCompleted($search);

0 commit comments

Comments
 (0)