Skip to content

Commit

Permalink
ID#323: introduced type hinting.
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Achatz committed Jun 30, 2018
1 parent be0f798 commit c891a5f
Show file tree
Hide file tree
Showing 22 changed files with 85 additions and 60 deletions.
2 changes: 1 addition & 1 deletion modules/comments/data/ArticleCommentMapper.php
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/contact/biz/ContactManager.php
Expand Up @@ -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);
}
Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion modules/contact/data/ContactMapper.php
Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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;
}

Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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;
Expand Down
Expand Up @@ -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.
Expand Down
Expand Up @@ -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();
}
Expand Down
Expand Up @@ -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');

Expand All @@ -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');

Expand Down
Expand Up @@ -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();
Expand Down
Expand Up @@ -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;
Expand Down
29 changes: 28 additions & 1 deletion tests/suites/tools/link/LinkGeneratorTest.php
Expand Up @@ -47,7 +47,7 @@ public function testSimpleLinkScheme() {
);
}

public function testUrlCreationFromString() {
public function testUrlCreationFromString1() {
$scheme = 'https';
$domain = 'www.domain.tld';
$path = '/path/to/dir';
Expand All @@ -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(
Expand Down Expand Up @@ -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(), []);
}

}
2 changes: 1 addition & 1 deletion tools/filesystem/FilesystemItem.php
Expand Up @@ -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());
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tools/html/taglib/GetIterator.php
Expand Up @@ -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);
}
Expand Down
26 changes: 13 additions & 13 deletions tools/link/Url.php
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
14 changes: 7 additions & 7 deletions tools/media/actions/StreamMediaAction.php
Expand Up @@ -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]);
Expand All @@ -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];
Expand Down Expand Up @@ -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'
];
}
}
Expand Down

0 comments on commit c891a5f

Please sign in to comment.