# 코딩 규칙

## 📍 PHP Code Tags

* 반드시 `<?php` 와 `<?=` 만을 사용한다.

> php 파일을 template 처럼 사용하는 경우, `echo` 태그는 가급적 `<?=` 를 사용한다.

#### Closing Tag

* PHP 소스 코드만 포함된 경우, `?>` 를 생략 한다.

## 📍Indenting

* `TAB`을 사용하지 않으며, 4자리의 `SPACE`를 사용한다.
* namespace, php open tag 레벨의 인덴트를 하지 않는다.

## 📍Control Structures

**Alternative syntax**

* Alternative syntax 를 사용하지 않는다.

**Curly brackets**

* `{`, `}` 사용시 줄바꿈 하지 않는다.

**Indenting**

* `{`, `}` 내부는 반드시 들여쓰기 한다.

**Control Statements**

* Control Keyword와 조건문 사이에는 반드시 1개의 `SPACE`가 포함되어야 한다.
* `else if` 대신 `elseif` 를 사용한다.

## 📍Forbidden Functions

* `sizeof` 대신 `count`를 사용한다.
* `delete` 대신 `unset`을 사용한다.
* `print` 대신 `echo`를 사용한다.
* `is_null` 대신 `if ($var === null);` 을 사용한다.
* `create_function` 대신 `anonymous function`을 사용한다.

## 📍Function Calls

* 메서드 또는 함수 호출시 `->`,`(`,`)`,`;` 사이에 `SPACE`가 포함되면 안된다.
* 각 Arguments 사이에 `SPACE`를 삽입한다.

## 📍Class Definitions

* 하나의 파일에는 하나의 클래스를 생성해야 한다.
* `{` 를 줄바꿈 한다.
* classloader 에서 클래스 경로를 찾을 수 있도록 namespace 를 정의한다.

#### Filenames

* 클래스명과 파일명이 일치해야 한다.
* classloader에서 클래스를 찾을 수 있도록 namespace 를 sub-directory 로 간주한 위치에 파일을 저장한다.

## 📍Function Definitions

* 함수명과 `(`, `)` 사이에 `SPACE`가 포함되면 안된다.
* 클래스와 마찬가지로 `{` 를 줄바꿈 한다.

#### Arguments

* 각 Argument 사이에 `SPACE`를 넣어 가독성을 높인다.

## 📍Comments

#### Inline Comment

* `//`만 사용한다.
* `#`을 사용하지 않는다.

**Block Comment**

* 2줄 이상의 inline comment 를 사용하지 않는다.

**Document Comments**

* 파일, 함수, 메소드, 프로퍼티, 클래스, 인터페이스에는 [phpDocumentor](https://www.phpdoc.org)형식의 Document Comments를 작성해야 한다.
* 구현 메소드의 Document Comments 는 {@inheritDoc} 태그를 사용한다.

#### Task Tags

* @todo 키워드를 주석에 사용하여 추가 작업에 대한 내용을 기록해 둘 수 있다.

> TODO, FIXME, XXX 는 사용하지 않는다.

## 📍File Formats

* BOM 이 없는 UTF-8 인코딩을 사용한다.
* 파일 인코딩을 혼용하지 않는다. (ex: EUC-KR 환경에서 AJAX 처리를 위해 일부 파일을 UTF-8로 저장하는 행위)
* 줄바꿈 문자는 Unix 타입의 `LF` 만을 사용한다.
* 줄끝 공백 제거 처리한다.
* 파일의 맨 마지막 라인에 빈 공백 라인을 추가한다.

## 📍 Etc

#### Operators

* 모든 연산자 앞, 뒤로 1개의 공백을 삽입한다.
* `Ternary Operator`는 중첩 사용하지 않고, 중간 구문을 생략 사용하지 않는다.
* `Error Control Operators`(@) 를 사용하지 않는다.

#### Strings

* `"` 대신 `'` 를 사용한다.
* SQL문 과 같이 내부에 `'` 가 쓰일 수 있는 경우 `"` 사용을 허용한다.
* [Heredoc syntax](http://php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc)를 사용하지 않는다.

#### Arrays

* 배열을 여러줄로 정의할 경우 마지막 원소의 끝에 `,`를 추가한다.
* 배열 선언시 가급적 축약형 구문을 사용한다.<br>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://devcenter-help.nhn-commerce.com/guide/base-information/structure/coding-rules.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
