Thiemo Mättig (WMDE) has uploaded a new change for review. ( 
https://gerrit.wikimedia.org/r/371477 )

Change subject: Add lots and lots of missing type hinted documentation
......................................................................

Add lots and lots of missing type hinted documentation

Change-Id: I20978d875f7d70270ccd652f60f75cdf989bd726
---
M src/JsonLdRdfWriter.php
M src/N3Quoter.php
M src/N3RdfWriterBase.php
M src/NTriplesRdfWriter.php
M src/RdfWriterBase.php
M src/TurtleRdfWriter.php
M src/UnicodeEscaper.php
M src/XmlRdfWriter.php
8 files changed, 161 insertions(+), 7 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/purtle refs/changes/77/371477/1

diff --git a/src/JsonLdRdfWriter.php b/src/JsonLdRdfWriter.php
index 184b826..578a0fe 100644
--- a/src/JsonLdRdfWriter.php
+++ b/src/JsonLdRdfWriter.php
@@ -11,13 +11,41 @@
  * @author C. Scott Ananian
  */
 class JsonLdRdfWriter extends RdfWriterBase {
-       protected $context = [];
+
+       /**
+        * @var string[]
+        */
+       private $context = [];
+
+       /**
+        * @var array[]
+        */
        private $graph = [];
+
+       /**
+        * @var array
+        */
        private $predicates = [];
+
+       /**
+        * @var array
+        */
        private $values = [];
+
+       /**
+        * @var bool
+        */
        private $wroteGraph = false;
+
+       /**
+        * @var bool
+        */
        private $disableGraphOpt = false;
 
+       /**
+        * @param string $role
+        * @param BNodeLabeler|null $labeler
+        */
        public function __construct( $role = parent::DOCUMENT_ROLE, 
BNodeLabeler $labeler = null ) {
                parent::__construct( $role, $labeler );
 
@@ -41,10 +69,19 @@
                };
        }
 
+       /**
+        * @return bool
+        */
        private function isTopLevel() {
                return $this->role === self::DOCUMENT_ROLE;
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        *
+        * @return string
+        */
        private function contextify( $base, $local = null ) {
                $this->expandShorthand( $base, $local );
 
@@ -106,7 +143,13 @@
                $this->write( "}" );
        }
 
-       private function encode( $val, $indent=0 ) {
+       /**
+        * @param array $val
+        * @param int $indent
+        *
+        * @return string
+        */
+       private function encode( $val, $indent = 0 ) {
                $str = json_encode( $val, JSON_PRETTY_PRINT | 
JSON_UNESCAPED_SLASHES );
                // add extra indentation
                $str = str_replace( "\n", "\n" . str_repeat( "    ", $indent ), 
$str );
@@ -136,6 +179,10 @@
                } );
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        */
        protected function writeSubject( $base, $local = null ) {
                $this->predicates = [
                        "@id" => $this->contextify( $base, $local )
@@ -146,10 +193,18 @@
                $this->graph[] = $this->predicates;
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        */
        protected function writePredicate( $base, $local = null ) {
                // no op
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        */
        protected function writeResource( $base, $local = null ) {
                $predBase = $this->currentPredicate[0];
                $predLocal = $this->currentPredicate[1];
@@ -167,6 +222,10 @@
                }
        }
 
+       /**
+        * @param string $text
+        * @param string|null $language
+        */
        protected function writeText( $text, $language = null ) {
                if (
                        $language === null ||
@@ -181,6 +240,11 @@
                }
        }
 
+       /**
+        * @param string $literal
+        * @param string|null $typeBase
+        * @param string|null $typeLocal
+        */
        public function writeValue( $literal, $typeBase, $typeLocal = null ) {
                if ( $typeBase === null && $typeLocal === null ) {
                        $this->values[] = $literal;
diff --git a/src/N3Quoter.php b/src/N3Quoter.php
index bc117e8..70aae88 100644
--- a/src/N3Quoter.php
+++ b/src/N3Quoter.php
@@ -23,6 +23,11 @@
                $this->escaper = $escapeUnicode ? new UnicodeEscaper() : null;
        }
 
+       /**
+        * @param string $iri
+        *
+        * @return string
+        */
        public function escapeIRI( $iri ) {
                //FIXME: apply unicode escaping?!
                return strtr( $iri, [
@@ -39,6 +44,11 @@
                ] );
        }
 
+       /**
+        * @param string $s
+        *
+        * @return string
+        */
        public function escapeLiteral( $s ) {
                // String escapes. Note that the N3 spec is more restrictive 
than the Turtle and TR
                // specifications, see 
<https://www.w3.org/TeamSubmission/n3/#escaping>
diff --git a/src/N3RdfWriterBase.php b/src/N3RdfWriterBase.php
index c8fdd97..1c8a3fb 100644
--- a/src/N3RdfWriterBase.php
+++ b/src/N3RdfWriterBase.php
@@ -15,6 +15,11 @@
         */
        protected $quoter;
 
+       /**
+        * @param string $role
+        * @param BNodeLabeler|null $labeler
+        * @param N3Quoter|null $quoter
+        */
        public function __construct(
                $role = parent::DOCUMENT_ROLE,
                BNodeLabeler $labeler = null,
@@ -57,7 +62,12 @@
                }
        }
 
-       protected function writeValue( $value, $typeBase = null, $typeLocal = 
null ) {
+       /**
+        * @param string $value
+        * @param string|null $typeBase
+        * @param string|null $typeLocal
+        */
+       protected function writeValue( $value, $typeBase, $typeLocal = null ) {
                $value = $this->quoter->escapeLiteral( $value );
                $this->write( '"' . $value. '"' );
 
diff --git a/src/NTriplesRdfWriter.php b/src/NTriplesRdfWriter.php
index dd2a468..fe77337 100644
--- a/src/NTriplesRdfWriter.php
+++ b/src/NTriplesRdfWriter.php
@@ -8,6 +8,11 @@
  */
 class NTriplesRdfWriter extends N3RdfWriterBase {
 
+       /**
+        * @param string $role
+        * @param BNodeLabeler|null $labeler
+        * @param N3Quoter|null $quoter
+        */
        public function __construct(
                $role = parent::DOCUMENT_ROLE,
                BNodeLabeler $labeler = null,
@@ -73,7 +78,12 @@
                parent::writeText( $text, $language );
        }
 
-       protected function writeValue( $value, $typeBase = null, $typeLocal = 
null ) {
+       /**
+        * @param string $value
+        * @param string|null $typeBase
+        * @param string|null $typeLocal
+        */
+       protected function writeValue( $value, $typeBase, $typeLocal = null ) {
                $this->writeSubjectAndObject();
                $this->write( ' ' );
 
diff --git a/src/RdfWriterBase.php b/src/RdfWriterBase.php
index 13b4669..4a2ed69 100644
--- a/src/RdfWriterBase.php
+++ b/src/RdfWriterBase.php
@@ -600,7 +600,7 @@
         * @note: $typeBase and $typeLocal are given as passed to value() and 
processed by expandType().
         *
         * @param string $value the value encoded as a string
-        * @param string $typeBase
+        * @param string|null $typeBase
         * @param string|null $typeLocal
         */
        abstract protected function writeValue( $value, $typeBase, $typeLocal = 
null );
@@ -639,7 +639,7 @@
         * Perform any expansion (shorthand to qname, qname to IRI) desired
         * for type identifiers.
         *
-        * @param string &$base
+        * @param string|null &$base
         * @param string|null &$local
         */
        protected function expandType( &$base, &$local ) {
diff --git a/src/TurtleRdfWriter.php b/src/TurtleRdfWriter.php
index 43e5ae4..7ba3425 100644
--- a/src/TurtleRdfWriter.php
+++ b/src/TurtleRdfWriter.php
@@ -9,6 +9,7 @@
  * @author Daniel Kinzler
  */
 class TurtleRdfWriter extends N3RdfWriterBase {
+
        /**
         * @var bool
         */
@@ -28,6 +29,11 @@
                $this->trustIRIs = $trustIRIs;
        }
 
+       /**
+        * @param string $role
+        * @param BNodeLabeler|null $labeler
+        * @param N3Quoter|null $quoter
+        */
        public function __construct(
                $role = parent::DOCUMENT_ROLE,
                BNodeLabeler $labeler = null,
diff --git a/src/UnicodeEscaper.php b/src/UnicodeEscaper.php
index 98f2357..bfb7a41 100644
--- a/src/UnicodeEscaper.php
+++ b/src/UnicodeEscaper.php
@@ -40,10 +40,14 @@
  */
 class UnicodeEscaper {
 
-       private $escChars = []; // Character encoding cache
+       /**
+        * @var string[] Character encoding cache
+        */
+       private $escChars = [];
 
        /**
         * @param string $str
+        *
         * @return string
         */
        public function escapeString( $str ) {
@@ -59,6 +63,11 @@
                return $result;
        }
 
+       /**
+        * @param string $cUtf
+        *
+        * @return int
+        */
        private function unicodeCharNo( $cUtf ) {
                $bl = strlen( $cUtf ); /* binary length */
                $r = 0;
@@ -85,6 +94,11 @@
                return $r;
        }
 
+       /**
+        * @param string $c
+        *
+        * @return string
+        */
        private function escapedChar( $c ) {
                $no = $this->unicodeCharNo( $c );
                /* see http://www.w3.org/TR/rdf-testcases/#ntrip_strings */
diff --git a/src/XmlRdfWriter.php b/src/XmlRdfWriter.php
index 74a1132..1f94cdf 100644
--- a/src/XmlRdfWriter.php
+++ b/src/XmlRdfWriter.php
@@ -12,6 +12,10 @@
  */
 class XmlRdfWriter extends RdfWriterBase {
 
+       /**
+        * @param string $role
+        * @param BNodeLabeler|null $labeler
+        */
        public function __construct( $role = parent::DOCUMENT_ROLE, 
BNodeLabeler $labeler = null ) {
                parent::__construct( $role, $labeler );
 
@@ -29,6 +33,11 @@
                };
        }
 
+       /**
+        * @param string $text
+        *
+        * @return string
+        */
        private function escape( $text ) {
                return htmlspecialchars( $text, ENT_QUOTES );
        }
@@ -49,6 +58,12 @@
                $this->expandQName( $base, $local );
        }
 
+       /**
+        * @param string $ns
+        * @param string $name
+        * @param string[] $attributes
+        * @param string|null $content
+        */
        private function tag( $ns, $name, $attributes = [], $content = null ) {
                $sep = $ns === '' ? '' : ':';
                $this->write( '<' . $ns . $sep . $name );
@@ -73,6 +88,10 @@
                }
        }
 
+       /**
+        * @param string $ns
+        * @param string $name
+        */
        private function close( $ns, $name ) {
                $sep = $ns === '' ? '' : ':';
                $this->write( '</' . $ns . $sep . $name . '>' );
@@ -135,6 +154,10 @@
                $this->write( "\n" );
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        */
        protected function writeSubject( $base, $local = null ) {
                $attr = $this->getTargetAttributes( 'about', $base, $local );
 
@@ -161,10 +184,18 @@
                $this->write( "\n" );
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        */
        protected function writePredicate( $base, $local = null ) {
                // noop
        }
 
+       /**
+        * @param string $base
+        * @param string|null $local
+        */
        protected function writeResource( $base, $local = null ) {
                $attr = $this->getTargetAttributes( 'resource', $base, $local );
 
@@ -173,6 +204,10 @@
                $this->write( "\n" );
        }
 
+       /**
+        * @param string $text
+        * @param string|null $language
+        */
        protected function writeText( $text, $language = null ) {
                $attr = $this->isValidLanguageCode( $language )
                        ? [ 'xml:lang' => $language ]
@@ -188,6 +223,11 @@
                $this->write( "\n" );
        }
 
+       /**
+        * @param string $literal
+        * @param string|null $typeBase
+        * @param string|null $typeLocal
+        */
        public function writeValue( $literal, $typeBase, $typeLocal = null ) {
                $attr = $this->getTargetAttributes( 'datatype', $typeBase, 
$typeLocal );
 

-- 
To view, visit https://gerrit.wikimedia.org/r/371477
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I20978d875f7d70270ccd652f60f75cdf989bd726
Gerrit-PatchSet: 1
Gerrit-Project: purtle
Gerrit-Branch: master
Gerrit-Owner: Thiemo Mättig (WMDE) <thiemo.maet...@wikimedia.de>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to