New environment with minted

\documentclass[12pt]{article}
\usepackage{minted}    
\makeatletter
\newenvironment{mycode}[3]
 {\VerbatimEnvironment
  \minted@resetoptions
  \setkeys{minted@opt}{frame=single}% from fancyvrb
  \renewcommand{\minted@proglang}[1]{#1}
  \begin{figure}[htp]%% default placing
    \centering
    \caption{#2}\label{#3}
      \begin{VerbatimOut}{\jobname.pyg}}
 {\end{VerbatimOut}
  \minted@pygmentize{\minted@proglang{}}
  \DeleteFile{\jobname.pyg}
  \end{figure}}
\makeatother

\begin{document}
\begin{mycode}{latex}{some caption}{code:label}
My \code here
\end{mycode}

\end{document}

enter image description here


You don't need so complicated a code:

\documentclass[12pt]{article}
\usepackage{minted}

\newenvironment{mycode}[4][]
 {\VerbatimEnvironment
  \begin{listing}
  \caption{#3}\label{#4}
  \begin{minted}[
    linenos,
    fontfamily=courier,
    fontsize=\scriptsize,
    xleftmargin=21pt,
    #1]{#2}}
 {\end{minted}\end{listing}}

\begin{document}

\begin{mycode}{latex}{some caption}{code:label}
My \code here
\end{mycode}

\begin{mycode}[fontsize=\large]{latex}{some caption}{code:label2}
My \code here
\end{mycode}

\end{document}

enter image description here