Skip to content
Permalink
Browse files

ID#323: introduced type hinting.

  • Loading branch information...
Christian Achatz
Christian Achatz committed Jun 30, 2018
1 parent be0f798 commit c891a5f3965e817f2073609a1aa4efd5c597ade4
@@ -46,7 +46,7 @@ class ArticleCommentMapper extends APFObject {
* @version
* Version 0.1, 22.08.2007<br />
*/
public function loadArticleCommentByID($commentId) {
public function loadArticleCommentByID(string $commentId) {
$SQL = $this->getConnection();
$select = 'SELECT ArticleCommentID, Name, EMail, Comment, Date, Time
@@ -167,7 +167,7 @@ private function getNotificationText(array $values = []) {
* @version
* Version 0.1, 19.10.2011<br />
*/
private function fillPlaceHolders($text, array $values = []) {
private function fillPlaceHolders(string $text, array $values = []) {
foreach ($values as $key => $value) {
$text = str_replace('{' . $key . '}', $value, $text);
}
@@ -188,7 +188,7 @@ private function fillPlaceHolders($text, array $values = []) {
* @version
* Version 0.1, 19.10.2011<br />
*/
private function getEmailTemplateContent($namespace, $template) {
private function getEmailTemplateContent(string $namespace, string $template) {
$loader = RootClassLoader::getLoaderByNamespace($namespace);
$rootPath = $loader->getRootPath();
$vendor = $loader->getVendorName();
@@ -83,7 +83,7 @@ public function loadRecipients() {
* Version 0.2, 04.06.2006<br />
* Version 0.3, 04.03.2007<br />
*/
public function loadRecipientById($id) {
public function loadRecipientById(string $id) {
/* @var $recipients ContactFormRecipient[] */
$recipients = $this->loadRecipients();
@@ -33,7 +33,7 @@
*/
class UmgtGroupCondition extends UserDependentContentConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
if ($user === null) {
return false;
@@ -31,7 +31,7 @@
*/
class UmgtLoggedInCondition extends UserDependentContentConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
return $user !== null;
}
@@ -31,7 +31,7 @@
*/
class UmgtLoggedOutCondition extends UserDependentContentConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
return $user === null;
}
@@ -34,7 +34,7 @@
*/
class UmgtNotPermissionCondition extends UserDependentContentConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
if ($user === null) {
return true;
@@ -31,7 +31,7 @@
*/
class UmgtNotRoleCondition extends UmgtRoleConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
if ($user === null) {
return true;
@@ -33,7 +33,7 @@
*/
class UmgtPermissionCondition extends UmgtRoleConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
if ($user === null) {
return false;
@@ -31,7 +31,7 @@
*/
class UmgtRoleCondition extends UmgtRoleConditionBase implements UserDependentContentCondition {
public function matches($conditionKey, UmgtUser $user = null) {
public function matches(string $conditionKey, UmgtUser $user = null) {
if ($user === null) {
return false;
@@ -39,7 +39,7 @@ interface UserDependentContentCondition {
*
* @return boolean true in case the condition matches, false otherwise.
*/
public function matches($conditionKey, UmgtUser $user = null);
public function matches(string $conditionKey, UmgtUser $user = null);
/**
* @return string The condition key.
@@ -49,7 +49,7 @@ abstract class UmgtBaseController extends BaseDocumentController {
* @version
* Version 0.1, 26.12.2008<br />
*/
protected function generateLink($linkParams, $baseURL = null) {
protected function generateLink(array $linkParams = [], $baseURL = null) {
if ($baseURL === null) {
$baseURL = $this->getRequest()->getRequestUri();
}
@@ -129,7 +129,7 @@ public function transformContent() {
* @version
* Version 0.1, 21.05.2011<br />
*/
private function loadUser($username, $password) {
private function loadUser(string $username, string $password) {
/* @var $umgt UmgtManager */
$umgt = $this->getDIServiceObject('APF\modules\usermanagement\biz', 'UmgtManager');
@@ -151,7 +151,7 @@ private function loadUser($username, $password) {
}
}
public function createAutoLogin($user) {
public function createAutoLogin(UmgtUser $user) {
/* @var $umgt UmgtManager */
$umgt = $this->getDIServiceObject('APF\modules\usermanagement\biz', 'UmgtManager');
@@ -108,8 +108,6 @@ public function transformContent() {
} elseif ($form->isSent() && !$form->isValid()) {
// error message
$form->setPlaceHolder('resetpw-error', $this->getTemplate('resetpw-error')->transformTemplate());
} else {
// nothing to do here
}
$form->transformOnPlace();
@@ -146,7 +146,7 @@ public function transformContent() {
}
private function getMarkerClass(FormControl &$control) {
private function getMarkerClass(FormControl $control) {
$marker = $control->getAttribute(AbstractFormValidator::$CUSTOM_MARKER_CLASS_ATTRIBUTE);
if (empty($marker)) {
$marker = AbstractFormValidator::$DEFAULT_MARKER_CLASS;
@@ -47,7 +47,7 @@ public function testSimpleLinkScheme() {
);
}
public function testUrlCreationFromString() {
public function testUrlCreationFromString1() {
$scheme = 'https';
$domain = 'www.domain.tld';
$path = '/path/to/dir';
@@ -61,6 +61,23 @@ public function testUrlCreationFromString() {
$this->assertEquals($paramValue, $url->getQueryParameter($paramName));
}
public function testUrlCreationFromString2() {
$this->expectException(UrlFormatException::class);
Url::fromString('////');
}
public function testUrlCreationFromReferrer1() {
$this->expectException(UrlFormatException::class);
Url::fromReferrer();
}
public function testUrlCreationFromReferrer2() {
$_SERVER['HTTP_REFERER'] = '/foo';
$url = Url::fromReferrer();
$this->assertEquals('/foo', $url->getPath());
unset($_SERVER['HTTP_REFERER']);
}
public function testFrontControllerUrlGeneration() {
$url = Url::fromString('')->setHost('localhost')->setScheme('http');
$link = LinkGenerator::generateUrl(
@@ -595,4 +612,14 @@ public function testEncodeRfc3986() {
$this->assertEquals('/?a[x]=1&a[y]=2&b[0]=1&b[1]=2&param name=param value', $link);
}
public function testResetQuery() {
$query = ['foo' => 'bar', 'bar' => 'baz'];
$url = new Url(null, null, null, null, $query);
$this->assertEquals($url->getQuery(), $query);
$url->resetQuery();
$this->assertEquals($url->getQuery(), []);
}
}
@@ -190,7 +190,7 @@ public function getOwner() {
* @version Version 0.1, 01.05.2012
*/
public function getParentFolder() {
return new Folder($this->getBasePath());
return (new Folder())->open($this->getBasePath());
}
/**
@@ -40,7 +40,7 @@ trait GetIterator {
*
* @return Iterator
*/
public function getIterator($name) {
public function getIterator(string $name) {
/* @var $this DomNode */
return $this->getChildNode('name', $name, Iterator::class);
}
@@ -59,7 +59,7 @@ final class Url {
* @version
* Version 0.1, 29.03.2011<br />
*/
public function __construct($scheme, $host, $port, $path, array $query = [], $anchor = null) {
public function __construct(string $scheme = null, string $host = null, int $port = null, string $path = null, array $query = [], string $anchor = null) {
$this->scheme = $scheme;
$this->host = $host;
$this->port = $port;
@@ -80,7 +80,7 @@ public function __construct($scheme, $host, $port, $path, array $query = [], $an
* @version
* Version 0.1, 29.03.2011<br />
*/
public static function fromString($url) {
public static function fromString(string $url) {
// the ugly "@" is only introduced to convert the E_WARNING into an exception
$parts = @parse_url($url);
@@ -123,7 +123,7 @@ public static function fromString($url) {
* Version 0.1, 29.03.2011<br />
* Version 0.2, 05.09.2015 (ID#258: support nested query parameters)<br />
*/
private static function getQueryParams($query) {
private static function getQueryParams(string $query = null) {
// reverse resolve encoded ampersands
$query = str_replace('&amp;', '&', $query);
@@ -152,7 +152,7 @@ private static function getQueryParams($query) {
* Version 0.1, 29.03.2011<br />
* Version 0.2, 09.03.2013 (Now uses standard PHP variables in stead of a Registry value to allow better url input filter manipulation)<br />
*/
public static function fromCurrent($absolute = false) {
public static function fromCurrent(bool $absolute = false) {
return self::getRequestStatic()->getUrl($absolute);
}
@@ -168,7 +168,7 @@ public static function fromCurrent($absolute = false) {
* @version
* Version 0.1, 07.09.2011<br />
*/
public static function fromReferrer($absolute = false) {
public static function fromReferrer(bool $absolute = false) {
return self::getRequestStatic()->getReferrerUrl($absolute);
}
@@ -187,7 +187,7 @@ public function getScheme() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setScheme($scheme) {
public function setScheme(string $scheme = null) {
$this->scheme = $scheme;
return $this;
@@ -208,7 +208,7 @@ public function getHost() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setHost($host) {
public function setHost(string $host = null) {
$this->host = $host;
return $this;
@@ -229,7 +229,7 @@ public function getPort() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setPort($port) {
public function setPort(int $port = null) {
$this->port = $port;
return $this;
@@ -250,7 +250,7 @@ public function getPath() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setPath($path) {
public function setPath(string $path = null) {
$this->path = $path;
return $this;
@@ -280,7 +280,7 @@ public function getQuery() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setQuery(array $query) {
public function setQuery(array $query = null) {
$this->query = $query;
return $this;
@@ -301,7 +301,7 @@ public function getAnchor() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setAnchor($anchor) {
public function setAnchor(string $anchor = null) {
$this->anchor = $anchor;
return $this;
@@ -319,7 +319,7 @@ public function setAnchor($anchor) {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function getQueryParameter($name, $default = null) {
public function getQueryParameter(string $name, $default = null) {
return isset($this->query[$name]) ? $this->query[$name] : $default;
}
@@ -373,7 +373,7 @@ public function resetQuery() {
* @version
* Version 0.1, 04.04.2011<br />
*/
public function setQueryParameter($name, $value) {
public function setQueryParameter(string $name, $value) {
$this->query[$name] = $value;
return $this;
@@ -99,7 +99,7 @@ public function run() {
*
* @return bool True in case the given extension is allowed, false otherwise.
*/
private function isAllowedExtension(array $extensions, $extension) {
private function isAllowedExtension(array $extensions, string $extension) {
$extension = strtolower($extension);
return isset($extensions[$extension]);
@@ -111,7 +111,7 @@ private function isAllowedExtension(array $extensions, $extension) {
*
* @return string Desired mime type,
*/
private function getMimeType(array $extensions, $extension) {
private function getMimeType(array $extensions, string $extension) {
$extension = strtolower($extension);
return $extensions[$extension];
@@ -185,12 +185,12 @@ private function getAllowedExtensions() {
return $this->getExtensions();
} catch (ConfigurationException $e) {
return [
'png' => 'image/png',
'png' => 'image/png',
'jpeg' => 'image/jpg',
'jpg' => 'image/jpg',
'gif' => 'image/gif',
'css' => 'text/css',
'js' => 'text/javascript'
'jpg' => 'image/jpg',
'gif' => 'image/gif',
'css' => 'text/css',
'js' => 'text/javascript'
];
}
}
Oops, something went wrong.

0 comments on commit c891a5f

Please sign in to comment.
You can’t perform that action at this time.