Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
CRAP
95.83% covered (success)
95.83%
23 / 24
N3RdfWriterBase
0.00% covered (danger)
0.00%
0 / 1
80.00% covered (warning)
80.00%
4 / 5
11
95.83% covered (success)
95.83%
23 / 24
 __construct
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
3 / 3
 writeRef
0.00% covered (danger)
0.00%
0 / 1
3.04
83.33% covered (warning)
83.33%
5 / 6
 writeIRI
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
4 / 4
 writeText
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
5 / 5
 writeValue
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
6 / 6
<?php
namespace Wikimedia\Purtle;
/**
 * Base class for RdfWriter implementations that output an N3 dialect.
 *
 * @license GPL-2.0-or-later
 * @author Daniel Kinzler
 */
abstract class N3RdfWriterBase extends RdfWriterBase {
    /**
     * @var N3Quoter
     */
    protected $quoter;
    /**
     * @param string $role
     * @param BNodeLabeler|null $labeler
     * @param N3Quoter|null $quoter
     */
    public function __construct(
        $role = parent::DOCUMENT_ROLE,
        BNodeLabeler $labeler = null,
        N3Quoter $quoter = null
    ) {
        parent::__construct( $role, $labeler );
        $this->quoter = $quoter ?: new N3Quoter();
    }
    /**
     * @param string $base
     * @param string|null $local
     */
    protected function writeRef( $base, $local = null ) {
        if ( $local === null ) {
            if ( $base === 'a' ) {
                $this->write( 'a' );
            } else {
                $this->writeIRI( $base );
            }
        } else {
            $this->write( "$base:$local" );
        }
    }
    /**
     * @param string $iri
     * @param bool $trustIRI
     */
    protected function writeIRI( $iri, $trustIRI = false ) {
        if ( !$trustIRI ) {
            $iri = $this->quoter->escapeIRI( $iri );
        }
        $this->write( "<$iri>" );
    }
    /**
     * @inheritDoc
     */
    protected function writeText( $text, $language = null ) {
        $value = $this->quoter->escapeLiteral( $text );
        $this->write( '"' . $value . '"' );
        if ( $this->isValidLanguageCode( $language ) ) {
            $this->write( '@' . $language );
        }
    }
    /**
     * @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 . '"' );
        if ( $typeBase !== null ) {
            $this->write( '^^' );
            $this->writeRef( $typeBase, $typeLocal );
        }
    }
}