<commit_before><?php
/**
 * Class to handle the communication between Jackalope and Jackrabbit via Davex.
 *
 * @license http://www.apache.org/licenses/LICENSE-2.0  Apache License Version 2.0, January 2004
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 * @package jackalope
 * @subpackage transport
 */

namespace Jackalope\Transport\DavexClient\Requests;

class NodeTypes implements \Jackalope\Interfaces\DavexClient\Request {

    /**
     * DOM representation of the request.
     * @var DOMDocument
     */
    protected $dom = null;

    /**
     * List of arguments to be handled.
     * @var array
     */
    protected $arguments = array();

    /**
     * Identifier of the used XML namespace
     * @var string
     */
    protected $nsPrefix = 'jcr';

    /**
     * URI of the used XML namespace
     * @var string
     */
    protected $nsUri = 'http://www.day.com/jcr/webdav/1.0';

    /**
     * Initiaties the NodeTypes request object.
     *
     * @param DOMDocument $dom
     * @param array $arguments
     */
    public function __construct($dom, $arguments) {
        $this->dom = $dom;
        $this->arguments = $arguments;
    }

    /**
     * Generates the DOMDocument representing the request to be send.
     *
     * @throws \InvalidArgumentException
     */
    public function build() {
        // root element
        //<jcr:nodetypes xmlns:jcr="http://www.day.com/jcr/webdav/1.0">
        $doc = $this->dom->createElementNS($this->nsUri, $this->nsPrefix.':nodetypes');

        // nodetypes
        if (!isset($this->arguments['nodetypes'])) {
            throw new \InvalidArgumentException('Missing NodeTypes.');
        }

        if (empty($this->arguments['nodetypes'])) {
            // <jcr:all-nodetypes/>
            $nType = $this->dom->createElement('jcr:all-nodetypes');
            $doc->appendChild($nType);
        } else {
            foreach ($this->arguments['nodetypes'] as $nodetype) {
                // '<jcr:nodetype><jcr:nodetypename>'.$nodetype.'</jcr:nodetypename></jcr:nodetype>';
                $nType = $this->dom->createElement('jcr:nodetype');
                $nTypeName = $this->dom->createElement('jcr:nodetypename', $nodetype);
                $nType->appendChild($nTypeName);
                $doc->appendChild($nType);<commit_msg>corrected implementation: moved arguments verification up to prevent from doing unnecessary work<commit_after><?php
/**
 * Class to handle the communication between Jackalope and Jackrabbit via Davex.
 *
 * @license http://www.apache.org/licenses/LICENSE-2.0  Apache License Version 2.0, January 2004
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *
 * @package jackalope
 * @subpackage transport
 */

namespace Jackalope\Transport\DavexClient\Requests;

class NodeTypes implements \Jackalope\Interfaces\DavexClient\Request {

    /**
     * DOM representation of the request.
     * @var DOMDocument
     */
    protected $dom = null;

    /**
     * List of arguments to be handled.
     * @var array
     */
    protected $arguments = array();

    /**
     * Identifier of the used XML namespace
     * @var string
     */
    protected $nsPrefix = 'jcr';

    /**
     * URI of the used XML namespace
     * @var string
     */
    protected $nsUri = 'http://www.day.com/jcr/webdav/1.0';

    /**
     * Initiaties the NodeTypes request object.
     *
     * @param DOMDocument $dom
     * @param array $arguments
     */
    public function __construct($dom, array $arguments) {
        $this->dom = $dom;
        $this->arguments = $arguments;
    }

    /**
     * Generates the DOMDocument representing the request to be send.
     *
     * @throws \InvalidArgumentException
     */
    public function build() {

        if (!isset($this->arguments['nodetypes'])) {
            throw new \InvalidArgumentException('Missing NodeTypes.');
        }

        // root element
        //<jcr:nodetypes xmlns:jcr="http://www.day.com/jcr/webdav/1.0">
        $doc = $this->dom->createElementNS($this->nsUri, $this->nsPrefix.':nodetypes');

        if (empty($this->arguments['nodetypes'])) {
            // <jcr:all-nodetypes/>
            $nType = $this->dom->createElement('jcr:all-nodetypes');
            $doc->appendChild($nType);
        } else {
            foreach ($this->arguments['nodetypes'] as $nodetype) {
                // '<jcr:nodetype><jcr:nodetypename>'.$nodetype.'</jcr:nodetypename></jcr:nodetype>';
                $nType = $this->dom->createElement('jcr:nodetype');
                $nTypeName = $this->dom->createElement('jcr:nodetypename', $nodetype);
                $nType->appendChild($nTypeName);
                $doc->appendChild($nType);
{'fraction_non_alphanumeric': 0.12764099877771956, 'fraction_numerical': 0.005587567661952156, 'mean_word_length': 2.5055079559363524, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '414582', 'n_tokens_mistral': 1661, 'n_tokens_neox': 1607, 'n_words': 444}